Home > OS >  Deserialize geojson from elasticsearch response into POJO
Deserialize geojson from elasticsearch response into POJO

Time:08-04

I'm trying to deserialize the response of elasticsearch using jackson. Everything works fine until I add geometry.

I'm using geolatte-geojson to handle geometry.

But for some reason the deserialization of elasticsearch response is not going well, probably 'cause in WKT format.

I've created a bean for geolatteModule for deserialization:

@Bean
public GeolatteGeomModule geomModule() {
    return new GeolatteGeomModule();
}

Here's how geometry response of elasticsearch looks like:

POLYGON((-95.26605606079102 29.724060758766743,-95.26631355285645 29.70900307937485,-95.23798942565917 29.702218931464575,-95.22185325622557 29.704306410402122,-95.2236557006836 29.72592417587012,-95.25712966918945 29.727638489043596,-95.26605606079102 29.724060758766743))

Here's how I'm trying to deserialize the response of elasticsearch to POJO:

Document document = objectMapper.convertValue(hit.getSourceAsMap(), Document.class);

Some additional points that might be helpful:
I'm also sending geometry object to DTO, when sending it as WKT I'm getting the same error. But when sending it in geojson format it works fine.

Error that I'm encountering:

java.lang.IllegalArgumentException: (was java.lang.NullPointerException) (through reference chain: com.kayrros.searchmanager.model.entity.Document["geometry"])
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4393)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:4324)

CodePudding user response:

If you want to get GeoJson back, you should just send GeoJson into your source documents instead of WKT, that way it'll be much easier than doing conversions from WKT to GeoJson on read.

  • Related