我有一个实体,其中一个属性是位置org.geolatte.geom.Point<G2D>。我为它创建了谷歌端点Transformer<Point<G2D>, String>,但收到以下错误:
直接自引用导致循环(通过引用链: com.example.package.MyEntity"location"->org.geolatte.geom.Point"envelope"->org.geolatte.geom.Envelope"coordinateReferenceSystem"->org.geolatte.geom.crs.Geographic2DCoordinateReferenceSystem"coordinateSystem"->org.geolatte.geom.crs.EllipsoidalCoordinateSystem2D"axes"->org.geolatte.geom.crs.GeodeticLongitudeCSAxis"unit"->org.geolatte.geom.crs.AngularUnit"fundamentalUnit"->org.geolatte.geom.crs.AngularUnit"fundamentalUnit") )的
com.fasterxml.jackson.databind.JsonMappingException:
为什么Jackson不能转换属性,以及应该如何转换?
发布于 2019-03-20 03:22:14
org.geolatte.geom.Point类扩展了具有Envelope<P> getEnvelope()方法的org.geolatte.geom.Geometry。默认情况下,Jackson序列化所有的POJO getters:get*和is*方法。您需要使用JsonIgnore注释忽略这些方法。示例MixIn接口可能如下所示:
interface GeometryMixIn {
@JsonIgnore
Envelope getEnvelope();
@JsonIgnore
PositionSequence getPositions();
}现在我们需要按如下方式注册它:
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(Geometry.class, GeometryMixIn.class);现在,您可以使用此映射器进行Point序列化。以防万一,其他getters也会有问题,以同样的方式忽略它们。但最好的OOP方式是创建自定义POJO,我们将基于Point创建它,其中我们可以完全控制3-rd party libraries可见的内容。
发布于 2019-03-20 02:38:01
我通过用org.locationtech.jts.geom.Point替换org.geolatte.geom.Point<G2D>来解决我的问题,但是我不知道为什么Point不能正常工作。
https://stackoverflow.com/questions/55246754
复制相似问题