commit | f426874421f28e996e107aed3370ad737f77931f | [log] [tgz] |
---|---|---|
author | Adrian Stabiszewski <github@grundid.de> | Wed Oct 09 09:13:17 2019 +0200 |
committer | GitHub <noreply@github.com> | Wed Oct 09 09:13:17 2019 +0200 |
tree | 5ccb6e7e4118ffb4a75dc1c68b67b04d9b7d563e | |
parent | f2becd4ce6f4f94695521f0eb57f1843006d7b9a [diff] | |
parent | 90ec0fea9b8d7e604123a972ea12bb62559135ff [diff] |
Merge pull request #51 from opendatalab-de/dependabot/maven/jackson-version-2.10.0 Bump jackson-version from 2.9.8 to 2.10.0
A small package of all GeoJson POJOs (Plain Old Java Objects) for serializing and deserializing of objects via JSON Jackson Parser.
If you know what kind of object you expect from a GeoJson file you can directly read it like this:
FeatureCollection featureCollection = new ObjectMapper().readValue(inputStream, FeatureCollection.class);
If you want to read any GeoJson file read the value as GeoJsonObject and then test for the contents via instanceOf:
GeoJsonObject object = new ObjectMapper().readValue(inputStream, GeoJsonObject.class); if (object instanceof Polygon) { ... } else if (object instanceof Feature) { ... }
and so on.
Or you can use the GeoJsonObjectVisitor to visit the right method:
GeoJsonObject object = new ObjectMapper().readValue(inputStream, GeoJsonObject.class); object.accept(visitor);
Writing Json is even easier. You just have to create the GeoJson objects and pass them to the Jackson ObjectMapper.
FeatureCollection featureCollection = new FeatureCollection(); featureCollection.add(new Feature()); String json= new ObjectMapper().writeValueAsString(featureCollection);
You can find the library in the Maven Central Repository.
<dependency> <groupId>de.grundid.opendatalab</groupId> <artifactId>geojson-jackson</artifactId> <version>1.8.1</version> </dependency>