Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support optional serialization/deserialization of map with non-string key type #3283

Open
pjfanning opened this issue Sep 21, 2021 · 1 comment

Comments

@pjfanning
Copy link
Member

Is your feature request related to a problem? Please describe.

Based on FasterXML/jackson-module-scala#316 and some other issues that have popped up where users want to work with Map<KeyClass, ValueClass> where the KeyClass can't be readily represented as a String.

Describe the solution you'd like

Typically, Maps (eg Map(1 -> "a", 2-> "b")) are serialized as something like:

{
  "1": "a",
  "2": "b"
}

But we could have a way to annotate this Map so that it gets serialized as:

[
  {
    "key": 1,
    "value": "a"
  },
  {
    "key": 2,
    "value": "b"
  }
]

The names of the JSON elements key and value could be made configurable.

This latter serialization could allow the key value to be represented as a JSON object or array.

This serialization might be useful for someone who wanted to JSON serialize a Map as opposed to using Java serialization.

Additional context
Not urgent. Just opened as a discussion topic. Users can currently write their own custom serializers and deserializers to achieve this.

@pjfanning pjfanning added the to-evaluate Issue that has been received but not yet evaluated label Sep 21, 2021
@cowtowncoder
Copy link
Member

Yeah this is sort of at the edge of what Jackson does do (allow support for slightly different structure/formatting) and does not (general structural transformations). I think I have heard this being desired occasionally so I think there is some demand for supporting this.

From API perspective, @JsonFormat(shape = xxx) could work, although might have to use funny semantics (default format would be NATURAL, but OBJECT seems bit ambiguous). And then again ability to specify overrides for "key" and "value" would require something different.

I'll leave this here for collecting more ideas (and finding someone with time and itch, too). Perhaps it could be tackled as some sort of datatype module, wherein more transformations could be applied...

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants