Desearializing a JSON which comes with an empty field
I'm trying to deserialize a JSON object like this:
public class Example {
private String a;
private int b;
private SubDataExample c;
//more fields, constructor, getters, etc
}
public class SubDataExample{
private String d;
private int e;
//more fields, constructor, getters, etc
}
It works well most cases, but开发者_如何学运维 sometimes SubData doesn't bring any data, I get JSON like this:
{"a":"blabla", b:843849, c:""}
Then, GSON fails and I get an exception. Would be possible to fill with a null the "c" field in the deserialized object?
I'm consuming a webservice that I haven't made, so, I have no option about changing the JSON that has to be deserialized.
I would appreciate your help
Thank you very much
I would expect that if there is no SubDataExample
, then you should get
{ "a": "blabla", "b": 843849, "c": null }
or
{ "a": "blabla", "b": 843849 }
精彩评论