Endre Deak
02/10/2023, 5:26 PM@Serializable
data class Foo(val name: String, val bar: Bar)
@Serializable
sealed class Bar
data class Bar1(val x: String) : Bar
data class Bar2(val y: Int): Bar
val foo1 = Foo("myFoo1", Bar1("Bar1"))
val foo2 = Foo("myFoo2", Bar2(2))
as JSON it should be
"myFoo1": { "type": "bar1", "x": "Bar1" }
"myFoo2": { "type": "bar2", "y": 2 }
jw
02/10/2023, 5:32 PM@SerialName("bar1")
on Bar
and @SerialName("bar2"
on Bar2
and you're doneFoo
?@Serializable
class Enclosing(
val one: Foo,
val two: Foo,
)
serialize as?Endre Deak
02/10/2023, 5:41 PMjw
02/10/2023, 5:43 PMEndre Deak
02/10/2023, 5:58 PMPERSON
and PHONE_NUMBER
, and there are multiple field sets that could go into that structure.
for example:
"anonymizers": {
"PERSON": {
"type": "redact"
},
"PHONE_NUMBER": {
"type": "replace",
"new_value": "ANONYMIZED"
}
}
I'm not sure how this could be created dynamicallyjw
02/10/2023, 6:00 PMList<Anonymizer>
and a custom serializer for the anonymizers
property which converted the list into the map. This goes back to what I was saying about the parent object owning the name, the anonymizers
serializer creates the parent object and thus can write names based on the child elements.Endre Deak
02/10/2023, 6:02 PMjw
02/10/2023, 6:03 PMEndre Deak
02/10/2023, 6:04 PM@Serializable
data class Request(
val anonymizers: Map<String, AnonymizerType>? = null
)
@Serializable
sealed class AnonymizerType
@Serializable
@SerialName("replace")
data class Replace(
@SerialName("new_value") val newValue: String
) : AnonymizerType()
@Serializable
@SerialName("redact")
object Redact : AnonymizerType()
// ...