/postgis-geojson

GeoJSON Jackson Serializers and Deserializers for PostGIS Geometry objects

Primary LanguageJavaMIT LicenseMIT

postgis-geojson

Build Status Release

GeoJSON Jackson Serializers and Deserializers for PostGIS Geometry objects.

GeoJSON Support

This library gives support for serialization/deserialization of all Geometry Objects defined in the GeoJSON specification.

The relation between GeoJSON geometry objects and PostGIS objects is given below:

GeoJSON PostGIS
Point Point
MultiPoint MultiPoint
LineString LineString
MultiLineString MultiLineString
Polygon Polygon
MultiPolygon MultiPolygon
GeometryCollection GeometryCollection

Installation

Add the JitPack repository to your <repositories> list in the pom.xml file:

<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

Then add the dependency to your pom.xml file:

<dependency>
  <groupId>com.github.mayconbordin</groupId>
  <artifactId>postgis-geojson</artifactId>
  <version>1.0</version>
</dependency>

For more information on how to build the library with other tools (Gradle, Sbt, Leiningen) see the JitPack documentation.

Usage

First you need to register the library module within the ObjectMapper instance you are going to use:

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

The 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);