Give a TypeScript interface: `interface Foo { foo?...
# serialization
p
Give a TypeScript interface: `interface Foo { foo?: integer | string }`how might I represent this in Kotlin with KXS?
My first inclination is to use
interface Foo { foo: SealedFoo? }
with
StringFoo(value: String) : SealedFoo
and
IntegerFoo(value: Int) : SealedFoo
but maybe there is something better.
b
I'm affraid not. PLus you;ll have to manage wrapping/unwrapping on kotlin side before passing the underlying values to js
p
I don't like my solution but I have it working with a JsonTransformationPolymorphicSerializer. An idea I have not worked out yet is to use
foo: Any?
with
Int
and
String
getting registered using @Contextual but I don't grok that yet.
fwiw, SealedClassSerializer showed me how to do my original better with a very slight tweak, enclosing the subclasses.