gpt4 book ai didi

hibernate - Jackson JSON View 与几何

转载 作者:行者123 更新时间:2023-12-03 06:58:56 24 4
gpt4 key购买 nike

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

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)

有人可以提出建议吗?

最佳答案

我遇到了以下错误,该错误被其他后续错误隐藏了:

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;
}

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

Geometry from vividsolutions JTS fails when creating JSON

关于hibernate - Jackson JSON View 与几何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14309981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com