I have a list of Java POJOs that all have a JTS geometry associated with them (Point) - a list of POIs, basically.

I want to output them as GeoJson (FeatureCollection, Feature etc.)

jackson-datatype-jts (https://github.com/bedatadriven/jackson-datatype-jts) will encode JTS Points into GeoJSON, but not a list of objects.

geojson-jackson (https://github.com/opendatalab-de/geojson-jackson) will let me make FeatureCollections and Features with geometries, but uses it's own classes for Geometries so I'd have to convert all of JTS to theirs.

That's not that complicated, but is there any Java library that will let me create proper GeoJson documents out of Java objects with JTS geometries? I started looking at GeoTools but can't really find any example that does that.

  • Have you looked at the current JTS version (Locationtech)? I suppose it has i/o for GeoJSON. OpenJUMP has also GeoJSON driver and source code might give you some inspiration.
    – user30184
    Oct 14, 2018 at 18:40
  • I did, but looks like newer versions of JTS only serialize Geometry objects, not arbitrary objects with JTS geometries inside.
    – kozyr
    Oct 15, 2018 at 0:24

1 Answer 1


If you look at GeometryJSON from GeoTools you will see the write method which should do what you need.

  • It seems like this would simply serialize the geometry, not the whole object. I want to get a JSON FeatureCollection array of Features as a result.
    – kozyr
    Oct 15, 2018 at 0:17
  • there is a GeoJSONDatastore that will serialize a GeoTools feature collection but if you want arbitrary POJOs you will need another lib + the GeoTools geometry handler.
    – Ian Turton
    Oct 15, 2018 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.