简体   繁体   English

杰克逊mixins抛出stackoverflow错误

[英]jackson mixins throwing stackoverflow error

Hi I'm writing a Rest service for a user object retrieved from common framework of my company. 嗨,我正在为从我公司的通用框架中检索的用户对象编写Rest服务。

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

The problem is the user object from common framework has an object with 2 getters for a String field like "isSomeflag()" and "getSomeflag()" I cannot modify the code from commonframework 问题是来自通用框架的用户对象具有一个对象,该对象具有2个用于字符串字段的getter的对象,例如“ isSomeflag()”和“ getSomeflag()”, 我无法从commonframework修改代码

I ended up using ** Jackson Mixins** but it is throwing stackoverflow error. 我最终使用了** Jackson Mixins **,但是它抛出了stackoverflow错误。 Any help will be appreciated. 任何帮助将不胜感激。

Code below 下面的代码

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

In service method: 使用方法:

@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);
}

Approach -2 方法-2

I tried creating local class with similar property and try mapping those properties from user object to local object. 我尝试创建具有类似属性的本地类,然后尝试将这些属性从用户对象映射到本地对象。 inital inference the problem class is referenced only once in user object 初始推断问题类仅在用户对象中被引用一次

But The problem is user contains many member object which in turn refer the problem object many times and I have to create many local copy of many classes from framework user structure 但是问题是用户包含许多成员对象,这些成员对象又多次引用该问题对象,因此我必须从框架用户结构中创建许多类的许多本地副本

Any solution for this 任何解决方案

Accoring to the documentation if the method in your base class are isSomeflag() and getSomeflag() . 根据文档,如果基类中的方法是isSomeflag()getSomeflag() You should use 你应该用

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

Ignore one and let the other be marshall with the JsonProperty. 忽略其中一个,让另一个与JsonProperty一起编组。

Also probably you are within a circular dependency that you need to break with jsonfilter, check this link 也可能您处于需要使用jsonfilter中断的循环依赖项中,请检查此链接

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM