Hello, I have a Java library and a Koltin library ...
# serialization
y
Hello, I have a Java library and a Koltin library is depending on the Java library. In the java library I have a class,
Foo.java
, Is that possible I can to mark it
@Serializable (with = ContextualSerializer<Foo>.class)
in side of Java, then use this
Foo.java
in my Kotlin library as it is
Serializable
, where inside of the Kotlin library, I define the
SerializerModule
(build a contextual serializer for Foo.java class and also a list of other classes), and then pass the
SerializerModule
to my custom ktxEncoder/ktxDecoder; The key point for me to doing this is to avoid define a Kotlin serializer for
Foo.java
in my Java library (we are trying to have at least Kotlin file in the Java lib as possible). Also trying to avoid the
@Contextual
annotation for my customers;
👎 1
b
I'm inclined to say it's not possible to mark a Java class with
@Serializable
, just because the serializers are generated by a kotlin compiler plugin (by manipulating kotlin's IR?)
You definitely could implement a serializer yourself though
p
You could use Moshi and write a kotlinx serializer that delegates to Moshi.