Roundtrip serialization of nested maps with empty value not working
See original GitHub issueI have a simple data class I am using to serialize into Redis. I have one field which is a nested string map like the following.
@SerialId(2) @Optional val groups: Map<String, Map<String, String>> = emptyMap()
I ran into an issue when this field contained a map that had an empty map as a value.
groups = mapOf("FOO" to emptyMap())
The object can be serialized without problem, but when you try to read the same object back and de-serialize it, you run into a missing required value exception. My guess is this is because the empty map is not serialized such that it can be brought back.
We got around it in our case by simply ignoring incoming data that would cause this problem, but I could see it popping back up in other places.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
serialization of a nested unordered_map with custom key ...
I suspect that the fact I declared the key as being const in the map declaration messes with the library, but I'm unable...
Read more >Jackson - Working with Maps and nulls - Baeldung
Jackson has a simple but useful way of globally controlling what happens to null values when a Map gets serialized:
Read more >Default mapping with JSON-B - IBM Developer
In this article, you'll be introduced to JSON-B's default mappings and automatic behaviors for serializing and deserializing most Java types ...
Read more >shasht | Quickdocs
These literals forms are only meant for serialization and not for round-trip mapping. Therefore there is no way to read JSON in the...
Read more >Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Hibernate not only takes care of the mapping from Java classes to database ... for map keys annotations, working on the principle that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, according to this (https://github.com/protocolbuffers/protobuf/issues/4596), nested maps in protobuf are not supported. It is possible to implement it in kotlinx.serialization though, but I don’t see much sense in it since it is a non-standard extension. I’d better add proper error message.
Fixed in 1.2.2 with 8f82c6b