簡體   English   中英

傑克遜mixins拋出stackoverflow錯誤

[英]jackson mixins throwing stackoverflow error

嗨,我正在為從我公司的通用框架中檢索的用戶對象編寫Rest服務。

用戶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

我嘗試創建具有類似屬性的本地類,然后嘗試將這些屬性從用戶對象映射到本地對象。 初始推斷問題類僅在用戶對象中被引用一次

但是問題是用戶包含許多成員對象,這些成員對象又多次引用該問題對象,因此我必須從框架用戶結構中創建許多類的許多本地副本

任何解決方案

根據文檔,如果基類中的方法是isSomeflag()getSomeflag() 你應該用

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

忽略其中一個,讓另一個與JsonProperty一起編組。

也可能您處於需要使用jsonfilter中斷的循環依賴項中,請檢查此鏈接

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM