enxt/jackson-datatype-jts


Jackson serializers for JTS Geometry objects

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

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

Add it in your build.sbt at the end of resolvers:

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

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.enxt:jackson-datatype-jts:2.5'
	}
	dependencies {
		implementation("com.github.enxt:jackson-datatype-jts:2.5")
	}
	<dependency>
	    <groupId>com.github.enxt</groupId>
	    <artifactId>jackson-datatype-jts</artifactId>
	    <version>2.5</version>
	</dependency>

                            
    libraryDependencies += "com.github.enxt" % "jackson-datatype-jts" % "2.5"
        
        

                            
    :dependencies [[com.github.enxt/jackson-datatype-jts "2.5"]]
        
        

Readme


Jackson-datatype-jts

Build Status Maven Release

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

Installation

Releases of jackson-datatype-jts are available on Maven Central.

Maven

To use the module in Maven-based projects, use following dependency:

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

Gradle

dependencies {
    compile 'com.bedatadriven:jackson-datatype-jts:2.2'
}

Usage

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