Skip to content

gjordi/jackson-datatype-jts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jackson Module which provides custom serializers and deserializers for JTS Geometry objects using the GeoJSON format

Maven dependency

To use module on Maven-based projects, use following dependency:

<dependency>
  <groupId>com.bedatadriven</groupId>
  <artifactId>jackson-datatype-jts</artifactId>
  <version>1.0</version>
</dependency>    

(or whatever version is most up-to-date at the moment)

Registering module

To use JTS geometry datatypes with Jackson, you will first need to register the module first (same as with all Jackson datatype modules):

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

Reading and Writing Geometry types

After registering JTS module, Jackson Databind will be able to write Geometry instances as GeoJSON and and read GeoJSON geometries as JTS Geometry objects.

To write a Point object as GeoJSON:

GeometryFactory gf = new GeometryFactory();
Point point = gf.createPoint(new Coordinate(1.2345678, 2.3456789));
String geojson = objectMapper.writeValueAsString(point);

You can also read GeoJSON in as JTS geometry objects:

InputStream in;
Point point = mapper.readValue(in, Point.class);

rusticus derrick- klantmonitoring@ing.nl 058 295 660

About

Jackson serializers for JTS Geometry objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%