Gson ignores null when deserializing an object

I want to deserialize a json string containing a null value in Java. I want to deserialize an object to a Properties object. The json line looks something like this:

 {"prop1":null, "propr2":"fancy value"} 

When I deserialize with

 String json = // new Gson().fromJson(json, Properties.class); 

I get a null pointer exception due to the Hastable that is in the Properties object. How can I instruct Gson to ignore null deserialization?

+5
source share
1 answer

See http://sites.google.com/site/gson/gson-user-guide#TOC-Null-Object-Support :

Gson gson = new GsonBuilder().serializeNulls().create();

-4
source

Source: https://habr.com/ru/post/1234361/


All Articles