我正在与Jackson合作进行JSON序列化。通常情况下,我回来的结构被命名并且很容易处理,但我遇到了一个我无法得到一个为此工作的POJO。有关如何将以下内容解析为集合POJO的任何建议吗?
JSON:
[
{
"transaction":
{
"accountType":"type",
"action":"A",
"created_at":"2011-08-16T17:41:48Z",
"id":1,
"sbAccountId":5,
"updated_at":"2011-08-16T17:41:48Z",
"userId":"1234",
"userName":"userName"
}
},
{
"transaction":
{
"accountType":"type",
"action":"A",
"created_at":"2011-08-16T17:41:48Z",
"id":1,
"sbAccountId":5,
"updated_at":"2011-08-16T17:41:48Z",
"userId":"1234",
"userName":"userName"
}
}
]
POJO:
@JsonIgnoreProperties(ignoreUnknown=true)
public class TransactionShell
{
private SbAccount transaction;
public TransactionShell() {}
public SbAccount getTransaction() {
return transaction;
}
public void setTransaction(SbAccount transaction) {
this.transaction = transaction;
}
}
反序列化调用:
List<TransactionShell> transactions = Common.mapper.readValue(responseBody, new TypeReference<List<TransactionShell>>() {});