All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gu.sql2java.geometry.jackson.GeometryDeserializer Maven / Gradle / Ivy

There is a newer version: 5.2.0
Show newest version
package gu.sql2java.geometry.jackson;

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 com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;

/**
 * Deserialize WKT property as Geometry Object with Jackson
* @author guyadong * @param * @since 3.18.0 */ 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); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy