杰克逊混合抛出计算器错误

jackson mixins throwing stackoverflow error

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

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

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

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

代码如下

    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

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

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

任何解决方案

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

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

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

也可能您处于需要使用 jsonfilter 打破的循环依赖中,检查此 link

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