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.

Add @JsonWrapped (to complement @JsonUnwrapped)

See original GitHub issue

Re-rasing this issue from the old Jira bug tracker:

It was suggested this should be raised in the data bind project, but as it is an annotation, this seemed a better fit.

This is the original issue description:

@JsonUnwrapped allows people who want a more compressed JSON hierarchy than their POJO to affect the process, but there is no option for the reverse. I have a REST service producing unnecessary additional layers of abstraction that i would like to exclude from my Java POJOs rather than writing all sorts of unseemly wrapper classes.

I agree this would be a great feature to avoid unnecessary wrappers on the Java side when consuming JSON APIs.

I’d picture a new annotation that would take a form along the lines of:

private String houseNumber;

or it could be an additional parameter of the @JsonProperty annotation:

@JsonProperty(value="house_number", wrapped="address")
private String houseNumber;

or, possibly, the value parameter of the @JsonProperty annotation could specify the object hierarchy:

private String houseNumber;

This may introduce backwards compatibility issues, though, as it would mean this behaved differently than it currently does.

It would be good if it could also unwrap multiple levels, such as:

private String houseNumber;

Though, this would mean the value of the @JsonWrapped annotation was parsed differently than the value of the @JsonProperty annotation (as "contact_details.address" in the @JsonProperty annotation would refer to an object key named “contact_details.address”).

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:45
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

cowtowncodercommented, Feb 1, 2021

Unlocking to allow use of reactions (use “thumbs up” to “vote”). Please no “+1” comments (content-containing comments welcome of course).

cowtowncodercommented, Sep 11, 2014

You are right in that annotation itself would be added here, but none of code handling it will be, which is why I think databind is actually better place for this. But that’s fine; we can even just have 2 issues, one for annotation, one for handling, mostly just to have entries for release notes for both.

As to multiple levels, I thought about that, and if that was to be supposed, I don’t think we can assume ‘.’ can be used as separator, since it is a legal property name character. But changing this to allow sequence of ids is easy, like:

@JsonWrapped({ "contact_details", "address" })

and Java annotations also allow omitting arrays to just do single as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

Luke Noel-Storr (JIRA) - org.codehaus.jackson.scm - MarkMail
[2]Re: Add @JsonWrapped (to complement @JsonUnwrapped) It seems this has been "In Progress" for quite a while, has much progress been made?
Read more >
JsonUnwrapped (Jackson-annotations 2.9.0 API) - FasterXML
Annotation can only be added to properties, and not classes, as it is contextual. Also note that annotation only applies if. Value is...
Read more >
FasterXML - Bountysource
@JsonUnwrapped allows people who want a more compressed JSON hierarchy ... Add support for specifying XML Schema attribute to output for root element...
Read more >
Jackson Annotations - @JsonUnwrapped - Tutorialspoint
Jackson Annotations - @JsonUnwrapped, @JsonUnwrapped is used to unwrap values of objects during serialization or de-serialization.
Read more >
Use jackson annotation JsonUnwrapped on a field with name ...
provide @JsonUnwrapped and @JsonProperty together: @JsonUnwrapped @JsonProperty("engine") private Engine myEngine;.
Read more >

github_iconTop Related Medium Post

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 Post

No results found

github_iconTop Related Hashnode Post

No results found