Java Google Endpoints transformer for org.geolatte.geom.Point
我有一个实体,其中一个属性是locationJava Google Endpoints transformer for org.geolatte.geom.Point,java,jackson,google-cloud-endpoints,Java,Jackson,Google Cloud Endpoints,我有一个实体,其中一个属性是locationorg.geolatte.geom.Point。我为它创建了Google EndpointsTransformer,但收到以下错误: com.fasterxml.jackson.databind.JsonMappingException:直接自引用导致循环(通过引用链:com.example.package.MyEntity[“location”]->org.geolatte.geom.Point[“envelope”]->org.geolatte.g
org.geolatte.geom.Point
。我为它创建了Google EndpointsTransformer
,但收到以下错误:
com.fasterxml.jackson.databind.JsonMappingException:直接自引用导致循环(通过引用链:com.example.package.MyEntity[“location”]->org.geolatte.geom.Point[“envelope”]->org.geolatte.geom.envelope[“CoordinaterReferenceSystem”]->org.geolatte.geom.crs.geographic2docationReferenceSystem[“CoordinationSystem”]->org.geolatte.geom.crs.椭球坐标系2D[“轴”]->org.geolatte.geom.crs.Geodeticontudecsaxis[“单位”]->org.geolatte.geom.crs.AngularUnit[“基本单元”]->org.geolatte.geom.crs.AngularUnit[“基本单元”])
为什么Jackson无法转换该属性以及如何转换?我通过将
org.geolatte.geom.Point
替换为org.locationtech.jts.geom.Point
解决了我的问题,但我不知道为什么Point不能正常工作。org.geolatte.geom.Point
类扩展了org.geolatte.geom.Geometry
,它有EnvelopegetEnvelope()
方法<默认情况下,code>Jackson序列化所有POJO
getter
:get*
和is*
方法。您需要使用JsonIgnore
annotation忽略这些方法。示例MixIn
界面可能如下所示:
interface GeometryMixIn {
@JsonIgnore
Envelope getEnvelope();
@JsonIgnore
PositionSequence getPositions();
}
现在我们需要注册如下:
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(Geometry.class, GeometryMixIn.class);
现在,您可以使用此映射器来点
序列化。在这种情况下,其他的getter
会有问题,以同样的方式忽略它们。但是最好的OOP
方法是创建自定义POJO
,我们将基于点创建该点,我们可以完全控制第三方库的可见内容