• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1GeoJson POJOs for Jackson
2=========================
3
4A small package of all GeoJson POJOs (Plain Old Java Objects) for serializing and
5deserializing of objects via JSON Jackson Parser.
6
7Usage
8-----
9
10If you know what kind of object you expect from a GeoJson file you can directly read it like this:
11
12
13```java
14FeatureCollection featureCollection =
15	new ObjectMapper().readValue(inputStream, FeatureCollection.class);
16```
17
18If you want to read any GeoJson file read the value as GeoJsonObject and then test for the contents via instanceOf:
19
20```java
21GeoJsonObject object = new ObjectMapper().readValue(inputStream, GeoJsonObject.class);
22if (object instanceof Polygon) {
23	...
24} else if (object instanceof Feature) {
25	...
26}
27```
28and so on.
29
30Or you can use the GeoJsonObjectVisitor to visit the right method:
31
32```java
33GeoJsonObject object = new ObjectMapper().readValue(inputStream, GeoJsonObject.class);
34object.accept(visitor);
35```
36
37
38Writing Json is even easier. You just have to create the GeoJson objects and pass them to the Jackson ObjectMapper.
39
40```java
41FeatureCollection featureCollection = new FeatureCollection();
42featureCollection.add(new Feature());
43
44String json= new ObjectMapper().writeValueAsString(featureCollection);
45```
46
47Maven Central
48-------------
49
50You can find the library in the Maven Central Repository.
51
52```xml
53<dependency>
54 <groupId>de.grundid.opendatalab</groupId>
55 <artifactId>geojson-jackson</artifactId>
56 <version>1.8.1</version>
57</dependency>
58```
59
60