Joshua Hansen
06/26/2025, 9:06 PMA
, that my application reads has changed. I used the JsonNames
annotation to account for properties that were simply renamed, but there is one property in particular whose name didn't change that went from being (in typescript speak) string[]
to { foo: string, bar: string[] }
. What's the best way to handle this property would could either be a list of strings or a specific class with two properties?
Should I:
• Create a custom serializer for this property which inspects the JSON structure of the property to determine which one it is?
• Create an entire alternative class for A
and use it as a surrogate after initially trying and failing to deserialize via the old format?
• Some other option?ephemient
06/26/2025, 10:49 PMJoshua Hansen
06/26/2025, 10:59 PMsealed class CustomProperty : List<String>
And then implement the list by delegation for the two subclasses:
@Serializable(with = OldSerializer::class)
data class Old(override val bar: List<String>) : CustomProperty(), List<String> by bar
@Serializable
data class New(val foo: String, override val bar: List<String>) : CustomProperty(), List<String> by bar
That way I don't have to worry about refactoring all the places it was originally just used as a list.Joshua Hansen
06/26/2025, 11:00 PM