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

Allow for multiple @JsonAnySetter when @JsonUnwrapped is supplied #2877

Open
raphw opened this issue Oct 10, 2020 · 4 comments
Open

Allow for multiple @JsonAnySetter when @JsonUnwrapped is supplied #2877

raphw opened this issue Oct 10, 2020 · 4 comments

Comments

@raphw
Copy link

raphw commented Oct 10, 2020

I am dealing with JSON where properties for certain areas are prefixed with given values. For example,

{
  "key" : "val1",
  "@key" : "val2",
  "$key" : "val3"
}

should be represented as a bean of three categories of property:

class Bean {
  @JsonAnySetter
  Map<String, String> normal;
  @JsonAnySetter
  @JsonUnwrapped(prefix = "@")
  Map<String, String> ats;
  @JsonAnySetter
  @JsonUnwrapped(prefix = "$")
  Map<String, String> dollars;
}

I understand that this is rather comples but the serialization works just fine. It would be brilliant being able to deserialize a JSON property if any property would only match one of the unwrapped specifications whereas any other property would end up in the non-unwrapped target.

@raphw raphw added the to-evaluate Issue that has been received but not yet evaluated label Oct 10, 2020
@cowtowncoder
Copy link
Member

Ah. Yes, I can see how combination would make sense wrt Map-bound @JsonUnwapped entries. Although TBH I think that is one case where use of @JsonAnySetter itself seems superfluous.

Use does not work currently, both in that only POJOs support unwrapping (second oldest open issue, #171) but I can see how that'd make sense.

@raphw
Copy link
Author

raphw commented Oct 11, 2020

Ah, I did not know that there was another open issue on this. I worked myself around this now using a serialization and deserialization converter that is generic enough to redirect any map's value to the correct collection but it is of course a bit tedious to maintain compared to the annotations. If the feature can ever make the cut, I think I'd be appreciated by a few powerusers but I see why this is not a top priority!

@cowtowncoder
Copy link
Member

It would be good to implement; problem lies more with implementation -- @JsonUnwrapped is bit of kludgey. And it has been easier to think of it as 3.0-only as rewrite of handling would be less risky.

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Nov 25, 2020
@alxxyz
Copy link

alxxyz commented Aug 2, 2022

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

4 participants
@cowtowncoder @raphw @alxxyz and others