opendatalab-de / geojson-jackson

GeoJson POJOs for Jackson - serialize and deserialize objects with ease
http://blog.opendatalab.de
Apache License 2.0
263 stars 94 forks source link

Serialization of List<Feature> does not include type #50

Open rmpt opened 5 years ago

rmpt commented 5 years ago

Serialization of feature lists should include the feature type. We are forced to use a FeatureCollection to the type be included in the serialization.

List<Feature> features = new ArrayList<>();
features.add(new Feature());
String json = new ObjectMapper().writeValueAsString(features);
System.out.println(json);
// output: [{"properties":{},"geometry":null}]
hylkevds commented 2 years ago

In case someone else runs into this, more background information can be found in this issue: https://github.com/FasterXML/jackson-databind/issues/1015

Workaround: instead of using List<Feature>, use:

private static class FeatureList extends ArrayList<GeoJsonObject> {};
private final FeatureList features = new FeatureList();