This repository was archived by the owner on Nov 30, 2025. It is now read-only.
Repository navigation
Serialization with JSON works but fails with YAML #189
|
I have a problem with custom serialization when using YAML. In the example below I want to serialize a <Map<String, String>> object like a <List<Map<String, String>>> object. With JSON this works flawlessly. With YAML I get an Exception that looks like this: Do you have any ideas why this fails? This is the code I used: |
Answered by
charleskorn
Oct 3, 2021
Replies: 1 comment 1 reply
|
Hi @m-31, thanks for the question. It looks like the issue might be the fact that 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 |
1 reply
Answer selected by
m-31
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @m-31, thanks for the question. It looks like the issue might be the fact that
descriptorin 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: