2014-04-14 29 views
0

我有一個使用solrj填充的列表類型字段,它使用getBean()方法將數據直接封送到bean。 solr字段被標記爲多值,但它確實是單值的。在其餘的響應中,我想將它作爲單個字符串傳輸。下面是代碼如何將球衣/傑克遜列表轉換爲字符串作爲迴應

@XmlRootElement 
@JsonSerialize(include = Inclusion.NON_NULL) 
@JsonIgnoreProperties(ignoreUnknown = true) 
public class Record { 

    @JsonIgnore 
    @Field //solrj field populated based on schema type 
    private List<String> titleList; 

    public String getTitle() { 
     if(titleList!= null && titleList.size() > 0) { 
      return titleList.get(0); 
     } 
     return ""; 
    } 
} 

當我從非球衣REST客戶端的響應對象我看到正確填充的字符串,但使用的球衣REST客戶端,我把它作爲空字符串「標題」字段。它如何被正確地反序列化爲所有REST客戶端的派生值?

我正在從Java客戶價值爲

Record response = target.queryParams(queryParams).request().buildGet().invoke(Record.class); 

鉻REST客戶端輸出 { 「稱號」: 「新趨勢」,

Jersey客戶端輸出 {
「稱號」: 「」,

回答

0

我使用@JsonIgnore來代替字段的getter和setter方法。這對於反序列化和序列化都有效

@Field("title") 
    private List<String> titleList; 

@JsonIgnore 
public List<String> getTitleList() { 
    return titleList; 
} 

@JsonIgnore 
public void setTitleList(List<String> titleList) { 
    this.titleList= titleList; 
} 

public String getTitle() { 
    if(titleList!= null && titleList.size() > 0) { 
     return titleList.get(0); 
    } 
    return null; 
} 
相關問題