commit | 8c6b8beaf3c721e5fbcdf37a6ea0464ec4c8b7cd | [log] [tgz] |
---|---|---|
author | Android Build Role Account android-build-prod <android-build-team-robot@google.com> | Thu Oct 15 18:46:26 2020 +0000 |
committer | Android Build Role Account android-build-prod <android-build-team-robot@google.com> | Thu Oct 15 18:46:26 2020 +0000 |
tree | 8a243f8c21b4db945d51a94d7f9ee8c64d21c303 | |
parent | cfd5e8ffb76c3bc3cf83a69eee64deadb5672f2d [diff] | |
parent | 8e898ac321e1344cf861ae8b7d10d48bc3caf0f0 [diff] |
Snap for 6908147 from 8e898ac321e1344cf861ae8b7d10d48bc3caf0f0 to s-keystone-qcom-release Change-Id: Ibeeff84e85dbdf9080ace373abe6aae139dd1566
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>