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

Add @JsonWrapped #512

Open
markwoon opened this issue Aug 3, 2014 · 26 comments
Open

Add @JsonWrapped #512

markwoon opened this issue Aug 3, 2014 · 26 comments
Labels
most-wanted Tag to indicate that there is heavy user +1'ing action

Comments

@markwoon
Copy link
Contributor

markwoon commented Aug 3, 2014

It would be nice to have the inverse of @JsonUnwrapped.

This would enable serializing this class:

class Gene {
  String symbol;
  String chrId;
  String chrName;
}

To this:

{
  "symbol" : "X",
  "chr" : { 
    "id" : "Y",
    "name": "chr1"
  }
}
@tgullotta
Copy link

+1

1 similar comment
@martinmecera
Copy link

+1

@cowtowncoder
Copy link
Member

I think use of JsonPointer expression would work well in expressing wrapping in JSON.
But how would one define grouping for fields to wrap? Something like..

@JsonWrapped({ @JsonWrapped.Group(path="/extra", fields={"b","c"}),
    @JsonWrapped.Group(path="/main", fields={"a"} })
public class Stuff {
   public int a, c, b;
}

to produce

{
   "main" : {
      "a" : 1
   },
   "extra" : {
     "b": 2,
     "c" : 3
   }
}

or such?

@markwoon
Copy link
Contributor Author

Can it be built up as we go along?

class Gene {
  String symbol;
  @JsonWraped(path="/chr", name="id")
  String chrId;
  @JsonWraped(path="/chr", name="name")
  String chrName;
}

This would make it simpler to refactor code if we don't have to worry about updating the field name in the annotation.

@cowtowncoder
Copy link
Member

I'd have to think about that, but my first thought was that it should be fine to use both @JsonProperty and @JsonWrapped to get this effect.

@Lobedan
Copy link

Lobedan commented Jan 17, 2015

+1

@cemo
Copy link

cemo commented Jan 17, 2015

I really love JsonUnwrapped concept and find quite useful. JsonWrapped would be a great asset for project.

+1

@gesellix
Copy link

+1
would love to have the inverse of JsonUnwrapped.

@poznachowski
Copy link

+1

3 similar comments
@vjkoskela
Copy link
Contributor

+1

@BrandonArp
Copy link

+1

@walkeros
Copy link

walkeros commented Jun 8, 2015

+1

@meonwax
Copy link

meonwax commented Jul 16, 2015

+1

3 similar comments
@happytomatoe
Copy link

+1

@soniro
Copy link

soniro commented Oct 14, 2015

+1

@jianghaolu
Copy link

+1

@Dru89
Copy link

Dru89 commented Oct 22, 2015

This probably belongs in jackson-annotations and is a duplicate of #42

@cowtowncoder
Copy link
Member

@Dru89 Actually this is the better place just because while annotations package is where annotation is added, databind implements the behavior. So one is needed for databind regardless. Having two different issues also works from release-notes perspective.

@manishpatelUK
Copy link

+1

1 similar comment
@ISchwarz23
Copy link

+1

@SemionPar
Copy link

+1 for reducing boilerplate

@marx-freedom
Copy link

+1

2 similar comments
@igorekpotworek
Copy link

+1

@altfatterz
Copy link

+1

@FasterXML FasterXML locked and limited conversation to collaborators Jul 25, 2016
@cowtowncoder
Copy link
Member

Pointless to add more +1s here; I take it there are users who would like to see this feature, so further "votes" have little additional value. Hence locking comments.

@cowtowncoder cowtowncoder changed the title Add @JsonWrapped Add @JsonWrapped Mar 30, 2017
@cowtowncoder cowtowncoder added 2.12 most-wanted Tag to indicate that there is heavy user +1'ing action labels Apr 12, 2020
@cowtowncoder
Copy link
Member

Note: added new "most-wanted" label to make it easier to find these Top Requests.

@cowtowncoder cowtowncoder added 2.13 and removed 2.12 labels Oct 14, 2020
@cowtowncoder cowtowncoder removed the 2.13 label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
most-wanted Tag to indicate that there is heavy user +1'ing action
Projects
None yet
Development

No branches or pull requests