package com.yb.postgis;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.google.common.base.Strings;
//import jdk.internal.joptsimple.internal.Strings;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
/**
* Deserialize WKT property as Geometry Object with Jackson
*
* @param
* @author guyadong
*/
public class GeometryDeserializer extends JsonDeserializer {
@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
try {
String text = jp.getValueAsString();
if (Strings.isNullOrEmpty(text)) {
return null;
}
WKTReader reader = new WKTReader();
return (T) reader.read(text);
} catch (ParseException e) {
throw new IOException(e);
}
}
}