Is it planned to have a mode of serialization that doesn't require deserialization and thus doesn't ...
a
Is it planned to have a mode of serialization that doesn't require deserialization and thus doesn't create the class discriminator with sealed classes/interfaces ?
e
can be done without kotlinx.serialization changes, but you lose type safety
actually this is basically just a weak form of `JsonContentPolymorphicSerializer`…
a
Thanks ! I'm basically in a project where I just need to generate hundred of different JSON schemas and never deserialiaze any of these. But because of the class discriminator being always generated, I need very often custom serializers with even ugly workarounds like setting the class discriminator to like
____do_not_use____
and traverse the JSON recursively to remove any field with that name
If you're curious about my project, I'm creating a big library for making Minecraft datapacks, with DSLs for every feature needing JSON, and there are a lot
a
a
@ephemient I tried your code and I'm getting
Parameter specified as non-null is null: method serializers.UntaggedPolymorphicSerializer.<init>, parameter kClass
🤔
Nevermind, it works, but not on sealed interfaces, which is problematic for me :/
e
if you're trying to match an external schema, my preference is always to automate generation of the Kotlin data structures from the canonical definitions. then you can also generate all of the serializers while you're at it.
a
I could, but nobody has already created schemas for this, maybe I could search inside the code of Minecraft (which is in Java) but it would be very complex, and I'm unsure how to do this Also the syntax is very complex and very often needs sealed classes or even
TypeOrOtherType
classes, for example
DoubleOrPairDouble
which is a class I have
a
@Ayfri I’m curious about this problem! Where are the Java data types? Do you have some source code I can look at? Maybe the Java classes could be auto-converted to Kotlin, and annotated with
@Serializable
? Perhaps the types are in another format (e.g. Json Schema) that could be auto converted to a Kotlin class?
a
I can't give you the classes legally, you have to search how to decompile Minecraft, take a look at Fabric or Quilt !