خرید بک لینک

Vote count: 0

I want to deserialize a JSON string using the same POJO for two king of messages. Take a look at the message below

{
"success": true,
"data": [
    {
        "id": 2,
        "Idea": null
    },
    {
        "id": 3,
        "Idea": null
    }
]
}

The data is an array, but sometimes the data is a single object:

{
"success": true,
"data":
    {
        "id": 2,
        "Idea": null
    }
}

My POJO looks like this:

public void setData(List<Object> data)
{
    this.data = data;
}

Is there any way to deserialize the second message (where data is not an array) using the same class?

Kind regards, Ricardo

asked 1 min ago

برچسب: jackson json deserialize list,jackson json serialize list of objects,jackson json serialize list,jackson json list serializer example,jackson json deserialize generic list, نویسنده: استخدام کار تاريخ: پنجشنبه 4 شهريور 1395 ساعت: 3:48

صفحه بندی