https://kotlinlang.org logo
#serialization
Title
# serialization
y

Yao-Wen Mei

07/12/2022, 7:30 PM
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

Ben Woodworth

07/13/2022, 7:28 PM
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

Paul Woitaschek

07/14/2022, 7:14 PM
You could use Moshi and write a kotlinx serializer that delegates to Moshi.
3 Views