hi, how can I make data class with empty arrays encode to empty json arrays? ``` val jsonMappe...
a
hi, how can I make data class with empty arrays encode to empty json arrays?
Copy code
val jsonMapper = Json {
        prettyPrint = true
        encodeDefaults = true
        coerceInputValues = true
      }
      val inputPet = Pet(
        name = petName,
        tags = emptyList(),
        photoUrls = emptyList(),
        status = petStatus
      )
      val inputPetJson = jsonMapper.encodeToString(inputPet)
Copy code
Actual :{"name":"blaaaah","status":"available"}
Expected:{"name":"blaaaah","photoUrls":[],"tags":[],"status":"available"}
I’ve tried various combinations of encodeDefaults and coerceInputValues. The problem is that
Pet
has other fields that default to null. I don’t want to include those.
d
Looks like a bug. File an issue.
a
in doing so I came up with a workaround - set the default value to null and manually set the parameter to emptyList() on creation