Would I need to define some sort of custom open or...
# serialization
z
Would I need to define some sort of custom open or closed polymorphic serializer, if my format doesn't cleanly allow a typetag, or
structure(string, value)
sequence, or otherwise made up of inline classes only?
This particular type of value is identifiable based on a marker in a different property. In JSON, it might be expressed like
Copy code
[
    { "name": "EDID", "value": "fJumpHeightMin" },
    { "name": "DATA", "value": 3000.0 }
]
The first letter of the
EDID
value indicates the type of value for
DATA
. • f for Float • s for String • b for Boolean • i for Int
Copy code
data class GMST(
    val edid: String,
    val data: GMSTData
)

sealed interface GMSTData

value class GMSTFloat(val float: Float) : GMSTData
value class GMSTString(val string: String) : GMSTData
value class GMSTBoolean(val boolean: Boolean) : GMSTData
value class GMSTInt(val int: Int) : GMSTData

val exampleFloat = GMST("fJumpHeightMin", GMSTFloat(3000f))
Would making the whole class be polymorphic make it easier, instead of just the data property?
Copy code
sealed interface GMST {
    val edid: String
}

data class GMSTFloat(
    override val edid: String,
    val float: Float
)
// ...