This modules provides a Jackson module to (de)serialize Geometry
, Feature
and FeatureCollection
instances to
(from) GeoJson.
Add the following dependency to the POM.
<dependency>
<groupId>org.geolatte</groupId>
<artifactId>geolatte-geojson</artifactId>
<version>${geolatte-geom-version}</version>
</dependency>
The library provides a custom module GeolatteGeomModule
that can be added to Jackson ObjectMapper
.
ObjectMapper mapper=new ObjectMapper();
mapper.registerModule(new GeolatteGeomModule());
Optionally you can customize the GeolatteGeomModule
behavior by:
- setting the default
CoordinateReferenceSystem
to use - setting a feature flag
You can configure a default Coordinate Reference System by passing it in the constructor of the GeolatteGeomModule
CoordinateReferenceSystem<G2D> crs=...;
ObjectMapper mapper=new ObjectMapper();
mapper.registerModule(new GeolatteGeomModule(crs));
If no default is specified in the constructor, the default will be set to WGS84
.
The default Coordinate Reference System will be used during deserialization from GeoJson whenever one of the following
conditions hold:
- the GeoJson
Geometry
doesn't have acrs
element - the
IGNORE_CRS
feature flag setting is set (see below)
You can set a feature flag after creation of the GeolatteGeomModule
:
GeolatteGeomModule module = new GeolatteGeomModule();
module.set(Setting.IGNORE_CRS, true);
mapper = new ObjectMapper();
mapper.registerModule(module);
The following settings are currently supported:
IGNORE_CRS
: ignore thecrs
element in the GeoJsonGeometry
(if any) and always use the default coordinate (default:false
)SUPPRESS_CRS_SERIALIZATION
: do not serialize acrs
object inGeometry
GeoJsons (default:false
)SERIALIZE_CRS_AS_URN
: serializecrs
as a URN (default:false
)