is there anything like a alias for SerialModule ? ...
# serialization
n
is there anything like a alias for SerialModule ? or any other way to move / refactor sealed classes and have it parse old json that has values for
type
?
d
Were you using the default
@SerialName
s before? You might have to explicitly use
@SerialName
with the old
type
s.
n
i can change it back so that the old code compiles.. but how would i migrate so that it recognizes
"type": "oldpackage.Type"
as a alias to
newpackage.Type
? or is manual intervention required ?
d
You'll need to annotate all the subclasses with,
@SerialName("oldpackage.Type")
.
n
which means that that key will end up in the json 😕
d
Oh, you want both to work!
n
i want both to parse but the new one to be what
stringify
outputs, if possible..
d
I think this is more/less what you're looking for https://github.com/Kotlin/kotlinx.serialization/pull/772 .
You can then register a "default" for the old names.
n
this looks like it could be useful..
d
It hasn't been released yet though, so will have to make due with a custom serializer. Like
JsonTransformingSerializer
.
You can use that to edit the types if they're old.
n
so i cannot use the
default {}
block quite yet since this is not in a release.. 😢 well i hope it will be available soon