构建一个POJO来使用Jackson解析这个JSON

时间:2011-08-16 20:38:59

标签: java json jackson

我正在与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>>() {});

0 个答案:

没有答案