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

Force root wrapping per class #33

Open
chrylis opened this issue May 7, 2014 · 16 comments
Open

Force root wrapping per class #33

chrylis opened this issue May 7, 2014 · 16 comments

Comments

@chrylis
Copy link

chrylis commented May 7, 2014

I'm working on mapping an external service that sends postbacks in wrapped JSON. I have set the @JsonRootName on the class and can read objects with a specially-configured mapper, but this wrapping behavior belongs to this service (i.e., a certain set of classes) specifically, and not to the overall system (Spring MVC, which expects a single mapping configuration).

Since it's known that this class will always need to be unwrapped, and request classes wrapped, it would be much clearer to be able to force root wrapping per class, perhaps with an alwaysWrap field on the @JsonRootName annotation. Is this a feasible feature?

@cowtowncoder
Copy link
Member

Yes, that sounds reasonable the way you suggest.

@cowtowncoder cowtowncoder added this to the 2.4.0 milestone May 8, 2014
@cowtowncoder
Copy link
Member

Added as suggested; need to add support in jackson-databind next.

@cowtowncoder
Copy link
Member

Hmmh. Actually, may need to re-think this one... unfortunately there is bit of a speed bump that I ignored earlier. Problem being that to find the flag, a lookup is needed. I need to think about this a bit more.

@cowtowncoder
Copy link
Member

Ok, I will have to revert this, since I don't think I can figure it out before 2.4.0 release. Will leave this open so that hopefully it can be included in 2.5.

cowtowncoder added a commit that referenced this issue May 8, 2014
@cowtowncoder
Copy link
Member

Note: was not included in 2.5.

@odrotbohm
Copy link

You might wanna clean up the JavaDoc on @JsonRootName accordingly as it still indicate the functionality might be (or better: have been, which it hasn't) introduced in 2.5.

Other than that, +1 for adding this :).

@ghost
Copy link

ghost commented Nov 26, 2015

Is there a plan to include this one in near future? We are quite depending on it, so we need to plan at least :)

@cowtowncoder
Copy link
Member

@jbm4sa No one working actively on this that I am aware of. Contributions welcome. But I will move this to jackson-databind as it is implement there, even if a tiny part may be relevant here; issues reported here are easier to ignore as well.

@cowtowncoder
Copy link
Member

Moved to FasterXML/jackson-databind#1022

@mdv27
Copy link

mdv27 commented Mar 2, 2016

Is there any way to remove default root wrapping? I want to send json without root element and I am not giving @JsonRootName still its wrapping with class name? Please suggest something. @chrylis @cowtowncoder

@cowtowncoder
Copy link
Member

@mv07517 Couple of ways. ObjectWriter has withoutRootName() method that can be used to do this for specific calls. Or, you may sub-class JacksonAnnotationIntrospector to sort of hide the annotation.

As to why root wrapping seems to be enabled in your case, I do not know. For questions, please use the mailing list in future; or, if you do have what you think is a bug, file a new issue with reproduction. Tagging questions to existing issues tends to make discussions more convoluted and harder to read.

@OndraZizka
Copy link

Any progress on this? I am looking at JacksonAnnotationIntrospector but see no way to do this. findRootName() doesn't affect this behavior.

@cxl-todd
Copy link

cxl-todd commented Sep 9, 2020

Seems like this is still commented out. Any thoughts on reintroducing this functionality? Would be great to do on a per-class basis rather than affecting the entire object mapper.

@cowtowncoder
Copy link
Member

@cxl-todd Unfortunately support was never implemented, even though annotation declaration was accidentally released.
If someone has time to look into this, I could help. But last I checked it seemed difficult to achieve. Esp. compared to relative ease with which one can just wrap root object in a simple Map to achieve the same effect.

@malloc32
Copy link

I need this functionally to, I need that object mapper only wrap root when class has the annotation. Any advance?
Thank you.

@cowtowncoder
Copy link
Member

@malloc32 for help with usage etc, mailing lists would be the place to ask, not issue. I can't think of anything simple that would do this automatically just based on annotation.

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

7 participants