Cookies Psst! Do you accept cookies?

We use cookies to enhance and personalise your experience.
Please accept our cookies. Checkout our Cookie Policy for more information.

A simple GeoJSON serializer for Jackson

When you are working with Geometry types in Postgis, if you are using a backend with Java and others JVM compatible languages, at some point you will need to send it as GeoJSON.

I was using Play Framework, which uses FasterXML/jackson for JSON serialization, but I couldn't find a suitable library for it. I found something but it was a bit outdated. The good news is that when it is Open Source, anything is a fork of distance :D

I made a fork and added support to get the SRID of any Geometry. I am not sure if it support all the use cases, but the good thing about Open Source software is that anyone can do a PR to improve things.

Any new test is welcome!

https://github.com/GeosatCO/postgis-geojson

Usage

After import it, you need to register the library module within the ObjectMapper instance you are going to use:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new PostGISModule());

Then you can serialize objects:

String json = mapper.writeValueAsString(new Point(125.6, 10.1));

And deserialize them:

Point point = (Point) mapper.readValue(json, Geometry.class);

Peace ✌

Last Stories

What's your thoughts?

Please Register or Login to your account to be able to submit your comment.