David David - 11 months ago 47
JSON Question

Android: parsing json with 'null' values using Gson

I got the following request from an Android developer:

Would you change the webservice back-end so that it returnes empty
for empty fields instead of null.

The Android json parser converts null to a string containing "null".

The code:

import com.google.gson.Gson;
private OrganizationSearchResult result;
Gson gson = new Gson();
result = gson.fromJson(resultString, OrganizationSearchResult.class);

Is this a known issue?

If so, is there a known work-around for it?


I dont know what you are using for parsing the json and the JSONObject class in android sdk doesnt do that.

Take a look at the following class


Check out has and isNULL of the above method.

I think GSON automatically handles the null in json by converting them to java null.