commit | 331c3ae524c731f2472e9be1c4c8d63623f5b67c | [log] [tgz] |
---|---|---|
author | android-build-team Robot <android-build-team-robot@google.com> | Sun Aug 09 03:05:28 2020 +0000 |
committer | android-build-team Robot <android-build-team-robot@google.com> | Sun Aug 09 03:05:28 2020 +0000 |
tree | 8a243f8c21b4db945d51a94d7f9ee8c64d21c303 | |
parent | ce0f71e6da075df9c09c7ba7943b4f694cfca800 [diff] | |
parent | 566d69914bcb89597c51e5df660b23b7fe59c42e [diff] |
Snap for 6748796 from 566d69914bcb89597c51e5df660b23b7fe59c42e to sc-d1-release Change-Id: I5d727bef3a74d49017d45cc98f3f2cde5d235784
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>