Java Google Endpoints transformer for org.geolatte.geom.Point

Java 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

我有一个实体,其中一个属性是location
org.geolatte.geom.Point
。我为它创建了Google Endpoints
Transformer
,但收到以下错误:

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
,我们将基于
点创建该点,我们可以完全控制
第三方库的可见内容