I am getting following response generated from the server by cakephp
[
{
"id": "42389",
"start": "0000-00-00",
"end": "0000-00-00",
"event_id": null,
"trip_id": "5791",
"location_id": "231552",
"user_id": "105",
"users_attending": "0",
"user_local": "0",
"Trip": {
"name": "Asdas"
},
"Event": [],
"Location": {
"name": "South Melbourne"
}
},
{
"id": "42392",
"start": "0000-00-00",
"end": "0000-00-00",
"event_id": "1218",
"trip_id": "4772",
"location_id": "271505",
"user_id": "105",
"users_attending": "3",
"user_local": "50",
"Trip": {
"name": "trip by 1059200"
},
"Event": {
"title": "SampleEvent 454",
"id": "1218"
},
"Location": {
"name": "Houston"
}
},
.......
]
The thing is that the parser expects Event object but if its null then it is receiving empty array.
Since the response is auto generated by cakephp, it has to be changed at a lot of places on server side.
Is there any simple way for jackson to ignore Event property if its an empty array??
EDIT:
I have tried having two properties with Event name: one array and other object but that too didn’t work.
Since, I had to handle response like this for many objects I finally went ahead with creating a generic class which would return a
Deserializerfor a specificclass.Here is what I used
}