mkporwit
11/26/2017, 7:17 AMdata class DocumentMetadata(val documentId: String, val documentType: DocumentType = DocumentType.SKETCH, val owners: MutableSet<String> = mutableSetOf())
and the following string representation:
{
"documentId": "__healthCheck",
"documentType": "SKETCH"
}
I'm trying to just do val meta:DocumentMetadata = Gson().fromJson(metaString)
, but owners comes up as null
in the deserialized type, instead of the expected empty set of strings. Is there some setting to get the default data class values for any elements not in the input string, or will I have to do a TypeAdapter
for this?Fré Dumazy
11/26/2017, 10:42 PMserializeNulls()
?
val gson = GsonBuilder()
.serializeNulls()
.create()
mkporwit
11/27/2017, 12:58 AMowners
field was added…mkporwit
11/27/2017, 1:01 AMdocumentType
, just a documentId
, I also get that as null, so I guess this is not a problem that is unique to collections.
But the bottom line remains the same — if fields are not specified in the string, I would like them to have the data class default values. Can I do that w/o a TypeAdapter
?