I'm using GSON with Retrofit. I want to disable empty array field deserialization.
DTO:
public class Entity implements Serializable {
@SerializedName("body")
@Expose
private BodyObject body;
I work with a rest API
. If the body field is empty then it send empty Array
:
{
"body": []
}
Exception:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 443 path $.body
If the body is filled, then they send the correct Object.
{
"body": {
"und": [
{
"value": "Test ....",
"summary": "",
"format": "filtered_html",
"safe_value": "<p>Test ....</p>\n",
"safe_summary": ""
}
]
}
}
-
Gson gson = new GsonBuilder()
.setLenient()
.create();
How can I delete, or disable these empty arrays deserializations?