2014-04-14 26 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; 
} 
相关问题