Skip to content

Serialization with JSON works but fails with YAML #189

Answered by charleskorn
m-31 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @m-31, thanks for the question. It looks like the issue might be the fact that descriptor in your custom serializer says that the serializer works with maps, but then receives a list. The JSON format is far more accepting of inconsistencies like these, but kaml requires them to be consistent so that it can report more detailed errors.

Something like this should work:

-override val descriptor: SerialDescriptor = MapSerializer(String.serializer(), String.serializer()).descriptor
+override val descriptor: SerialDescriptor = ListSerializer(MapSerializer(String.serializer(), String.serializer())).descriptor

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@m-31
Comment options

Answer selected by m-31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants