Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何将jersey/jackson列表转换为响应字符串_List_Serialization_Jersey - Fatal编程技术网

List 如何将jersey/jackson列表转换为响应字符串

List 如何将jersey/jackson列表转换为响应字符串,list,serialization,jersey,List,Serialization,Jersey,我使用solrj填充了一个列表类型字段,它使用getBean()方法将数据直接封送到bean。solr字段标记为多值,但实际上是单值的。在rest响应中,我希望将其作为单个字符串传输。这是密码 @XmlRootElement @JsonSerialize(include = Inclusion.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Record { @JsonIgnore @Fiel

我使用solrj填充了一个列表类型字段,它使用getBean()方法将数据直接封送到bean。solr字段标记为多值,但实际上是单值的。在rest响应中,我希望将其作为单个字符串传输。这是密码

@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 "";
    }
}
Chrome Rest客户端输出 { “标题”:“新趋势”

泽西客户端输出 {

“title”:“”

我在getter和setter方法上使用了@JsonIgnore,而不是field。这对反序列化和序列化都有效

@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;
}
@字段(“标题”)
私人列表标题列表;
@杰索尼奥雷
公共列表getTitleList(){
返回标题列表;
}
@杰索尼奥雷
公共无效设置标题列表(列表标题列表){
this.titleList=titleList;
}
公共字符串getTitle(){
if(titleList!=null&&titleList.size()>0){
返回标题列表。获取(0);
}
返回null;
}
@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;
}