3

我在 PostgreSQL DB + PostGIS 上使用 Spring + Hibernate Geometry,它在 DB 上执行 CRUD 操作并使用 Jackson JSON 视图返回 JSON 输出。在我添加Geometry. 当我检查对象时,搜索返回正确的输出,但是在创建结果的 JSON 表示时似乎存在问题,该结果具有Geometry. 我得到这样的东西:

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: This method does not support GeometryCollection arguments (through reference chain: java.util.ArrayList[0]->com.tutorial.jquery.model.State["geom"]->com.vividsolutions.jts.geom.MultiPolygon["boundary"]->com.vividsolutions.jts.geom.MultiLineString["boundary"]->com.vividsolutions.jts.geom.MultiPoint["boundary"]->com.vividsolutions.jts.geom.GeometryCollection["boundary"]); nested exception is org.codehaus.jackson.map.JsonMappingException: This method does not support GeometryCollection arguments (through reference chain: java.util.ArrayList[0]->com.tutorial.jquery.model.State["geom"]->com.vividsolutions.jts.geom.MultiPolygon["boundary"]->com.vividsolutions.jts.geom.MultiLineString["boundary"]->com.vividsolutions.jts.geom.MultiPoint["boundary"]->com.vividsolutions.jts.geom.GeometryCollection["boundary"])
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:195)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:179)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:148)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:90)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:189)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:69)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.codehaus.jackson.map.JsonMappingException: This method does not support GeometryCollection arguments (through reference chain: java.util.ArrayList[0]->com.tutorial.jquery.model.State["geom"]->com.vividsolutions.jts.geom.MultiPolygon["boundary"]->com.vividsolutions.jts.geom.MultiLineString["boundary"]->com.vividsolutions.jts.geom.MultiPoint["boundary"]->com.vividsolutions.jts.geom.GeometryCollection["boundary"])
at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:215)
at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:180)
at org.codehaus.jackson.map.ser.SerializerBase.wrapAndThrow(SerializerBase.java:128)

有人可以建议吗?

4

2 回答 2

0

您可以为 jackson 的几何类型注册自定义序列化器,例如,请参阅Custom Jackson Serializer for a specific type in a specific class。问题是,你希望它如何呈现为 json?通过 WKT 还是其他什么?

于 2021-06-23T14:29:04.507 回答
0

我有以下错误,被其他后续错误隐藏:

org.codehaus.jackson.map.JsonMappingException: This method does not 
support GeometryCollection arguments (through reference chain: 
com.mapflow.exposure.model.wrapper.DefaultWrapper["result"]->
java.util.ArrayList[0]->com.mapflow.exposure.model.poi.SimplePoint["geom"]->
com.vividsolutions.jts.geom.Point["boundary"]->
com.vividsolutions.jts.geom.GeometryCollection["boundary"]) 

原因看起来我们在 Weblogic 环境中使用了 Jackson 库(我们在 Tomcat 中使用了另一个运行良好的库)并且它无法处理几何属性。

我们@JsonIgnore在实体和它的 getter 中添加了属性声明:

import org.codehaus.jackson.annotate.JsonIgnore;
@JsonIgnore
private Geometry geom;
(...)
@JsonIgnore
public Geometry getGeom() {
    return geom;
}

我可以在这个问题中看到其他更复杂的方法,但我自己没有尝试过:

来自vividsolutions JTS的几何在创建JSON时失败

于 2016-03-23T15:50:07.420 回答