我有一张地图(由Json组成)如下,
{office=null, basicFunc=Brokerage Documents, id=null, status=Good, rcvdDateTime=08/01/2013 01:48:25, orgUnit=5L9890327, numOfPg=null, ip=null, content=null, btchName=ONLINE UPLOAD, docTypeCde=20130801, rqstId=null, filNm={subrecord={subfiled1=[value1, value2]}}, docSizeBytes=null, docId=1234567, doctype=ConversionAgreement}
并且POJO如下
public class IDocument {
private String basicFunc;
private String doctype;
private String orgUnit;
@JsonDeserialize(as=Subrecord.class,contentAs=Subrecord.class)
private Subrecord filNm;
private String content;
}
public class Subrecord {
private List<Subfiled1> subField1;
public List<Subfiled1> getSubField1() {
return subField1;
}
public void setSubField(List<Subfiled1> subField1) {
this.subField1 = subField1;
}
}
public class Subfiled1 {
private String value1;
private String value2;
public String getValue1() {
return value1;
}
public void setValue1(String value1) {
this.value1 = value1;
}
public String getValue2() {
return value2;
}
public void setValue2(String value2) {
this.value2 = value2;
}
}
我正在使用jackson将地图转换为IDocument对象,如下所示
ObjectMapper mapper = new ObjectMapper();
IDocument iDocObj = mapper.convertValue(map, IDocument.class);
在iDocObj中我能够获得除filnm之外的所有内容的值,它将变为空
iDocObj.getFilNm()。getSubField1()= null;
如何为getFilNm定义值。
答案 0 :(得分:0)
在你的JSON中它被命名为subfiled1而在java中它是subfield ...所以检查正确的命名约定