How can I say to GSON that if a JSON with an array field has NULL value, it has to create an empty array instead of setting a null?
are there any properties or Flags available for this?
How can I say to GSON that if a JSON with an array field has NULL value, it has to create an empty array instead of setting a null?
are there any properties or Flags available for this?
You can do some workaround before you pass your json to Gson.
String currentKeyTags = "\"KeyTags\":null";
String expectedKeyTags = "\"KeyTags\":[]";
String jsonArrayString= jsonArray.toString()
.replaceAll(currentKeyTags, expectedKeyTags);
Now:
Gson gson=new Gson();
Type listType = new TypeToken<List<?>>() {
}.getType();
List<?> lists = gson.fromJson(jsonArrayString, listType);