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

Convert POJO to JsonNode using a JsonView (via valueToTree?) #1687

Open
mkurz opened this issue Jul 3, 2017 · 6 comments
Open

Convert POJO to JsonNode using a JsonView (via valueToTree?) #1687

mkurz opened this issue Jul 3, 2017 · 6 comments
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x

Comments

@mkurz
Copy link

mkurz commented Jul 3, 2017

Right now it is not possible to apply a view to mapper.valueToTree(fromValue).
It would be nice to have an overloaded version like mapper.valueToTree(fromValue, MyView.class) (or similar).

As a workaround right now I use:

mapper.readTree(mapper.writerWithView(MyView.class).writeValueAsString(someValue))

to apply a view to an object I want to convert to a JsonNode.

Is there a better way to solve this?

Also have a look at this SOF discussion: https://stackoverflow.com/q/23006241/810109

@cowtowncoder
Copy link
Member

Hmmh. Ideally I think conversion functionality could be exposed either via ObjectReader or ObjectWriter, either of which does expose methods for selecting view to use. But the problem there is that conversion requires writing AND reading, so neither can do the whole processing.
On the other hand I really would prefer to avoid expanding set of method signatures ObjectMapper already has; and by this I mean that although this specific feature does not cause huge expansion one could thing of many other alternate conversion configuration methods that do.

So I'll have to think of what to do here: adding just this one method may be fine.

@mkurz
Copy link
Author

mkurz commented Jul 18, 2017

@cowtowncoder Thanks for your reply. If you could add just this one method that would be great. I have been working heavily with jackson but actually this was the only limitation I was facing so far.
I think this would be a great addition.
Thanks!

@mkurz
Copy link
Author

mkurz commented Jan 10, 2018

Any chance this will be fixed soon?

@cowtowncoder cowtowncoder added 3.x Issues to be only tackled for Jackson 3.x, not 2.x and removed 2.9 labels Jan 10, 2018
@cowtowncoder
Copy link
Member

No, I don't think so. It sounds like something that could be done for 3.0, so could be implemented in near future (if anyone has time for it, I don't). But would take a while to get released just because 3.0 (major API compatiblity breaking) is quite a way out.

But I think this would be good addition, potentially, if I understand it right.

@mkurz
Copy link
Author

mkurz commented May 19, 2019

Hey! Any news on this one? Do you think it's hard to implement this in upcoming version 3?

@cowtowncoder
Copy link
Member

@mkurz The main challenge is that there are so many things to work on, even on my "short list" of immediate work (https://github.com/FasterXML/jackson-future-ideas/wiki/Jackson-Work-in-Progress).

I don't think it would necessarily be difficult to do, although that depends on details. I'll add it to "simple" list of features for 3.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Projects
None yet
Development

No branches or pull requests

2 participants