gson: Treat null as empty String
The above answer works okay for serialisation, but on deserialisation, if there is a field with null value, Gson will skip it and won’t enter the deserialize method of the type adapter, therefore you need to register a TypeAdapterFactory and return type adapter in it. Gson gson = GsonBuilder().registerTypeAdapterFactory(new NullStringToEmptyAdapterFactory()).create(); public static class NullStringToEmptyAdapterFactory<T> implements … Read more