您好,我正在为从我公司的通用框架检索的用户对象编写一个 Rest 服务。
User userobj = commonframework.getuser(userid);//用户即接口(interface)
问题是来自通用框架的用户对象有一个带有 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
我尝试创建具有类似属性的本地类,并尝试将这些属性从用户对象映射到本地对象。 初步推断问题类在用户对象中仅被引用一次
但是问题是用户包含许多成员对象,这些成员对象又多次引用问题对象,我必须从框架用户结构创建许多类的许多本地副本
有什么解决办法吗
最佳答案
根据文档,如果您的基类中的方法是
isSomeflag()
和 getSomeflag()
。你应该使用
@JsonProperty("newProp") abstract int isSomeflag()
@JsonIgnore abstract int getSomeflag();
忽略其中一个,让另一个通过 JsonProperty 进行编码。
此外,您可能处于需要使用 jsonfilter 打破的循环依赖关系中,请检查此 link
FilterProvider filterProvider = new SimpleFilterProvider()
.addFilter("filtermixin", SimpleBeanPropertyFilter.serializeAllExcept("circulardependency"));
关于java - Jackson mixins 抛出 stackoverflow 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36366782/