【问题标题】:Spring Data Rest PersistentEntityResource Jackson serialization goes into StackOveflowErrorSpring Data Rest PersistentEntityResource Jackson 序列化进入 StackOveflowError
【发布时间】:2013-11-26 01:49:01
【问题描述】:

我正在使用最新的快照 spring-data-rest-webmvc:2.0.0-SNAPSHOT。 当 Jackson 尝试将 PersistentEntityResource 序列化为 JSON 时,它会进入“persistentEntity”属性的无限循环。我知道该属性应该被忽略,但事实并非如此。

public class PersistentEntityResource<T> extends Resource<T> {
    @JsonIgnore private final PersistentEntity<?, ?> entity;
    ...
    public PersistentEntity<?, ?> getPersistentEntity() {
        return entity;
    }
}

也许 Jackson 看到了与字段名称不匹配的 getter 并决定序列化?还是我配置有问题?

【问题讨论】:

    标签: java jackson spring-data-rest


    【解决方案1】:

    【讨论】:

    • 您为我指明了正确的方向。 @JsonIgnore 似乎存在问题,但真正的问题是我使用的是默认 ObjectMapper,而不是在 RepositoryRestMvcConfiguration 中配置的那个。所以这是两个问题的结合。
    【解决方案2】:

    我通过确保在 spring 上下文中没有另一个名为“objectMapper”的 bean 解决了这个问题。这是一个默认的 Jackson ObjectMapper,它覆盖了 RepositoryRestMvcConfiguration 中配置的自定义对象。

    【讨论】:

      猜你喜欢
      • 2018-04-17
      • 2017-07-21
      • 2017-07-04
      • 2018-11-07
      • 2019-02-27
      • 2016-07-01
      • 2017-09-14
      • 2012-09-25
      • 2023-03-14
      相关资源
      最近更新 更多