I'm working on Ser/De geojson use Genson.
So,I have Genson as base class and Feature(and a lot of others) as derived class.
I create a Deserializer with Genson Generic.
public class GeoJSONSerializer implements Deserializer<GeoJSON> {
@Override public GeoJSON deserialize(ObjectReader reader, Context ctx) throws Exception {
Map<String,Object> properties = new HashMap<>(); GeoJSON geoJSON = null;
reader.beginObject();
while (reader.hasNext()) {
reader.next();
switch (reader.name()) {
case "type":
geoJSON = createGeoJson(reader.valueAsString());
break;
case "properties":
properties.put("properties",ctx.genson.deserialize(new GenericType<JsonObject>(){}, reader, ctx));
break;
default:
reader.skipValue();
}
}
reader.endObject();
if(geoJSON != null) {
//set values
}
return geoJSON;
}
}
I want to return Polymorphic types from the deserialize method.I must instantiate object corresponding the value of 'type' in the Geojson.
Now I have a map to save all the values,and at last after I know the exactly type I do the assignment work.But in that way I will lost the benefit of Streaming.
How can I do that?
Can I use xpath in the ObjectReader or do some Sorting operation before deserialize?