Gson serialize null for specific class or field
I have a solution similar to the one of Aleksey but that can be applied to one or more fields in any class (example in Kotlin): Create a new annotation for fields that should be serialized as null: @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FIELD) annotation class SerializeNull Create a TypeAdapterFactory that checks if a class has fields annotated with … Read more