question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Roundtrip serialization of nested maps with empty value not working

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sandwwraithcommented, Apr 19, 2019

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.

0reactions
shanshincommented, Aug 31, 2021

Fixed in 1.2.2 with 8f82c6b

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found