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:
|
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
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: