/postgis-geojson

GeoJSON Jackson Serializers and Deserializers for PostGIS Geometry objects

Primary LanguageJavaMIT LicenseMIT

postgis-geojson

Release

GeoJSON Jackson Serializers and Deserializers for PostGIS Geometry objects.

Note: this is a fork from https://github.com/mayconbordin/postgis-geojson with updated dependencies, and improvements from https://github.com/sdeleuze/postgis-geojson

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.GeosatCO</groupId>
  <artifactId>postgis-geojson</artifactId>
  <version>1.6</version>
</dependency>

Or in a build.sbt:

resolvers += "jitpack" at "https://jitpack.io"

libraryDependencies += "com.github.GeosatCO" % "postgis-geojson" % "1.6"

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