【问题标题】:jackson mixins throwing stackoverflow error杰克逊mixins抛出stackoverflow错误
【发布时间】:2016-04-01 22:28:48
【问题描述】:

您好,我正在为从我公司的通用框架中检索到的用户对象编写一个 Rest 服务。

User userobj = commonframework.getuser(userid); //用户是接口

问题是来自通用框架的用户对象有一个带有 2 个 getter 的对象,用于字符串字段,如“isSomeflag()”和“getSomeflag()” 我无法从 commonframework 修改代码

我最终使用了 ** Jackson Mixins** 但它引发了 stackoverflow 错误。任何帮助将不胜感激。

代码如下

    public abstract class IgnoreMixin {
    @JsonIgnore 
    public abstract String isServiceOnlyflg();
}

在服方式:

@Produces(MediaType.APPLICATION_JSON)
public Response createUserInfo{
mapper = new ObjectMapper();
mapper.getSerializationConfig().addMixInAnnotations(DealerImpl.class,IgnoreMixin.class);
writer = mapper.writer().withDefaultPrettyPrinter();
return writer.writeValueAsString(userobj);
}

方法-2

我尝试创建具有相似属性的本地类,并尝试将这些属性从用户对象映射到本地对象。 初步推断问题类在用户对象中仅被引用一次

但问题是用户包含许多成员对象,这些成员对象又多次引用问题对象,我必须从框架用户结构中创建许多类的许多本地副本

任何解决方案

【问题讨论】:

  • 你能添加堆栈跟踪吗

标签: java json jackson jax-rs


【解决方案1】:

根据文档,如果您的基类中的方法是 isSomeflag()getSomeflag() 。你应该使用

 @JsonProperty("newProp") abstract int isSomeflag()
 @JsonIgnore abstract int getSomeflag();

忽略一个,让另一个与 JsonProperty 一起编组。

也可能你处于一个循环依赖中,你需要用 jsonfilter 打破,检查这个link

 FilterProvider filterProvider = new SimpleFilterProvider()
      .addFilter("filtermixin", SimpleBeanPropertyFilter.serializeAllExcept("circulardependency"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-24
    • 2019-05-19
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 2020-03-31
    • 1970-01-01
    相关资源
    最近更新 更多