You can use jackson-datatype-jts from this link .
Its integration with spring looks like this:
servlet.xml helper:
<mvc:annotation-driven > <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="objectMapper" ref="customObjectMapper"/> </bean> </mvc:message-converters> </mvc:annotation-driven> <bean id="customObjectMapper" class="my.server.util.CustomObjectMapper"/>
my.server.util.CustomObjectMapper:
package my.server.util; import com.bedatadriven.jackson.datatype.jts.JtsModule; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext; import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; import org.springframework.beans.factory.InitializingBean; public class CustomObjectMapper extends ObjectMapper implements InitializingBean{ public CustomObjectMapper() { } public CustomObjectMapper(JsonFactory jf) { super(jf); } public CustomObjectMapper(ObjectMapper src) { super(src); } public CustomObjectMapper(JsonFactory jf, DefaultSerializerProvider sp, DefaultDeserializationContext dc) { super(jf, sp, dc); } @Override public void afterPropertiesSet() throws Exception { this.registerModule(new JtsModule()); } }
Then in the rest of the controller, if you return the geometry, you can get it geojson.
source share