I am using resttemplate with Gson to deserialize the json data.
I am using List<Object> wherever it can send JSONArray output.
But the problem is whenever there is single entry/item it gives output in the form of JSONObject.
I such cases my deserializer gives exception as "Expected BEGIN_ARRAY but was BEGIN_OBJECT".
Please tell me how to solve this problem. Is there any good rest client library to use with android which can handle such kind of JSON data.
JSONArray example (for more than one item)
----------------------
{
"product":
[
{
"id": "11",
"name": "Bull Snort Cowboy Cayenne Pepper Hot Sauce",
"activeStartDate": "2013-05-07T14:09:39.197+05:30",
"manufacturer": "Brazos Legends",
"defaultSku":
{
"id": "11",
"activeStartDate": "2013-05-07T14:09:39.197+05:30",
"name": "Bull Snort Cowboy Cayenne Pepper Hot Sauce",
"retailPrice":
{
"amount": "3.99",
"currency": "USD"
}
},
"productOptions": null
},
{
"id": "12",
"name": "Cafe Louisiane Sweet Cajun Blackening Sauce",
"activeStartDate": "2013-05-07T14:09:39.198+05:30",
"manufacturer": "Garden Row",
"defaultSku":
{
"id": "12",
"activeStartDate": "2013-05-07T14:09:39.198+05:30",
"name": "Cafe Louisiane Sweet Cajun Blackening Sauce",
"retailPrice":
{
"amount": "4.99",
"currency": "USD"
}
},
"productOptions": null
}
]
}
JSONObject output (for single item)
----------------------
{
"product":
{
"id": "11",
"name": "Bull Snort Cowboy Cayenne Pepper Hot Sauce",
"activeStartDate": "2013-05-07T14:09:39.197+05:30",
"manufacturer": "Brazos Legends",
"defaultSku":
{
"id": "11",
"activeStartDate": "2013-05-07T14:09:39.197+05:30",
"name": "Bull Snort Cowboy Cayenne Pepper Hot Sauce",
"retailPrice":
{
"amount": "3.99",
"currency": "USD"
}
},
"productOptions": null
}
}
//note:- here square brackets removed for single item
This forum is in readonly mode and serves as an archive of old information. All posting, registration and commenting abilities have been turned off. To get help, the Broadleaf team reguarly monitors the broadleaf-commerce tag on Stack Overflow so please ask your questions there.