I am attempting to serialize with java.io.Serializable a Kotlin class that is already serializable with kotlinx.serialization. The java serialization will not work out of the box because some fields in the class are not serializable by default. But, there are already adapters for the kotlix.serialization. So, I am trying to add custom read and write methods (using the Externalizable interface) to the class, so that I can fallback to the kotlinx.serialization. Basicly it is something like this:
@Serializable
data class Foo(
val a: A \\ A is serializable in kotlinx and not in java.io
...
val z: Z \\ This is serializable in java.io
)
I tried to do the following in Kotlin:
@Serializable
data class Foo(
val a: A \\ A is serializable in kotlinx and not in java.io
...
val z: Z \\ This is serializable in java.io
): java.io.Externalizable {
override fun writeExternal(out: ObjectOutput?) {
TODO("Not yet implemented")
}
override fun readExternal(`in`: ObjectInput?) {
TODO("Not yet implemented")
}
}
I can't replace the values of the class in the read methods (they are immutable). This means I can't use serializable directly either. Is there a builtin way to do this?