We ran into issues in our project when we enabled GsonBuilder's serializeNulls() option and feed that Gson object to this client.
Specifically, this method in CouchDbUtils.java is problematic:
public static String getAsString(JsonObject j, String e)
{
return j.get(e) == null ? null : j.get(e).getAsString();
}
CouchDbClientBase invokes this method to get the _id and _rev properties. The problem we're facing is when Gson serializes nulls, (say {"_id": null}) - the logic above falls short. It invokes getAsString() on JsonNull, which doesn't override the base implementation of getAsString() from JsonElement. This ends up throwing UnsupportedOperationException().
Shouldn't the logic be more like this?
public static String getAsString(JsonObject j, String e)
{
return (j.get(e) == null || j.get(e).isJsonNull) ? null : j.get(e).getAsString();
}
Same applies to other getAs..() methods. What are your thoughts? Why was isJsonNull check skipped?
Hi,
We ran into issues in our project when we enabled GsonBuilder's serializeNulls() option and feed that Gson object to this client.
Specifically, this method in CouchDbUtils.java is problematic: public static String getAsString(JsonObject j, String e) { return j.get(e) == null ? null : j.get(e).getAsString(); }
CouchDbClientBase invokes this method to get the _id and _rev properties. The problem we're facing is when Gson serializes nulls, (say {"_id": null}) - the logic above falls short. It invokes getAsString() on JsonNull, which doesn't override the base implementation of getAsString() from JsonElement. This ends up throwing UnsupportedOperationException().
Shouldn't the logic be more like this? public static String getAsString(JsonObject j, String e) { return (j.get(e) == null
|| j.get(e).isJsonNull
) ? null : j.get(e).getAsString(); }Same applies to other getAs..() methods. What are your thoughts? Why was isJsonNull check skipped?