bjornharrtell / jts2geojson

JTS from/to GeoJSON converter for Java
MIT License
138 stars 56 forks source link

Null properties Jackson serializer - change null collection to empty one #31

Closed mrisney closed 5 years ago

mrisney commented 5 years ago

Running into an issue when using Geotools, GeoDataFactory. When parsing the GeoJSON, if no properties are present, getting a null instead of an empty pair of brackets. Is there a way the properties map could be configured so that properties : {} could be output instead of properties:null ?

Jackson 2.9 adds new properties to existing (but rarely used) @JsonSetter annotation to allow specifying one of common alternatives.

propose that org.wololo.geojson.Feature use the @JsonSetter annotation :

@JsonSetter(nulls = Nulls.AS_EMPTY)
public Map<String, Object> getProperties() {
    return properties;
}
bjornharrtell commented 5 years ago

I'm not sure I want to change from null to {} by default. From the spec it's clear that null is valid. What is the issue you are having with GeoTools?

mrisney commented 5 years ago

org.geotools.data.geojson.GeoJSONDataStore bombs out when trying to pass in a GeoJSON with properties:null. Workaround is

GeoJSONWriter writer = new GeoJSONWriter(); GeoJSON geoJSONObj = writer.write(features); String geoJSONStr = geoJSONObj.toString().replaceAll("null", "{}");

This is ugly.

bjornharrtell commented 5 years ago

To me, this seems like an issue with GeoTools.

mrisney commented 5 years ago

Mapbox https://github.com/mapbox/tippecanoe/issues/15