我从Solr的实例回来相当JSON响应Java对象....如何反序列化JSON到使用杰克逊
{"responseHeader":
{"status":0,"QTime":1,"params":{"sort":"score asc","fl":"*,score",
"q":"{! score=distance}","wt":"json","fq":"description:motor","rows":"1"}},
"response":{"numFound":9,"start":0,"maxScore":6.8823843,"docs":
[{"workspaceId":2823,"state":"MN","address1":"1313 mockingbird Lane",
"address2":"","url":"http://mydomain.com/","city":"Minneapolis",
"country":"US","id":"399068","guid":"","geo":["45.540239, -98.580473"],
"last_modified":"2012-12-12T20:40:29Z","description":"ELEC MOTOR",
"postal_code":"55555","longitude":"-98.580473","latitude":"45.540239",
"identifier":"1021","_version_":1421216710751420417,"score":0.9288697}]}}
而且我想映射到Java对象:
public class Item extends BaseModel implements Serializable {
private static final long serialVersionUID = 1L;
protected Integer workspaceId;
protected String name;
protected String description;
protected String identifier;
protected String identifierSort;
protected Address address;
protected String url;
/** getters and setters eliminated for brevity **/
}
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
protected String address1;
protected String address2;
protected String city;
protected String state;
protected String postalCode;
protected String country;
/** getters and setters eliminated for brevity **/
}
如何将地址1,地址2,城市,州等等映射到项目对象中的地址对象?我一直在阅读关于Jackson annotations,但没有真正跳到我从哪里开始。
你必须指定你所尝试的。有不同的方法http://mattgemmell.com/2008/12/08/what-have-you-tried/ –
你有没有考虑过使用SolrJ?您可能会发现更方便,无论是解开响应还是构建查询。 –
@Eric我没有,但完全愿意看看它。你有没有一个你认为是开始的好地方? – kasdega