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

Jackson @JsonView deserialization support for request bodies [SPR-12501] #17106

Closed
spring-issuemaster opened this issue Dec 3, 2014 · 9 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Dec 3, 2014

Ersin Er opened SPR-12501 and commented

#11815 added support for @JsonView for response bodies. The same can also be applied to request bodies as Jackson already supports @JsonView for deserialization.

@RequestMapping(value = "/persons", consumes = APPLICATION_JSON_VALUE, method = RequestMethod.POST)
public ResponseEntity<Person> savePerson(@JsonView(View.Summary.class) @RequestBody Person p)
{
    return new ResponseEntity<>(personRepository.save(p), HttpStatus.OK);
}

Affects: 4.1.2

Attachments:

Issue Links:

  • #11815 Integrate Jackson @JsonView
  • #17828 JsonView support for JMS
  • #17856 Jackson @JsonView deserialization support for @MessageMapping payloads
  • #17859 Allow @JsonView to be used on meta-annotations on Rest methods

4 votes, 9 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 4, 2014

Sébastien Deleuze commented

Hi Ersin Er,

Your proposal makes sense but @JsonView is currently not applicable to parameters, only to methods and fields.
I have raised an issue on Jackson bugtracker about that, let's see what is their answer.

Sébastien

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 4, 2014

Sébastien Deleuze commented

Good news, starting Jackson 2.5.0 @JsonView will also target method parameters!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 16, 2015

Enrique Ruiz (DiSiD) commented

It would be great if the JSON data binding process would follow the same process of Validation, Data Binding, and Type Conversion than the one done by HTTP forms.

Imho the custom validations, data binding and type conversions would be able to be applied to both JSON messages and HTTP messages.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 13, 2015

Andrew Thorburn commented

I would love to see this feature, and I was having a look to see if I could get it working with just a few tweaks and maybe extending the jackson message converters, but no dice - the AbstractJackson2HttpMessageConverter has no idea what annotations are attached to the parameter, so it can't fetch the necessary annotation information - that's held one level up, by AbstractMessageConverterMethodArgumentResolver, but it's not passed into the actual message converter. Is there an easy way of dealing with this, or does it require broader changes to the Spring message conversion?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 15, 2015

Enrique Ruiz (DiSiD) commented

Sébastien, do you see this feature useful? Can we collaborate in any way?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 15, 2015

Sébastien Deleuze commented

Enrique Ruiz (DiSiD) Do you talk about "@JsonView deserialization support" or "JSON data binding process following the same process of Validation, Data Binding, and Type Conversion than HTTP forms" ?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 20, 2015

Mikhail Sokolov commented

I wrapped Type into ExtendedType that holds both originalType and additional info - view class. Look at the patch attached.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 2, 2015

Enrique Ruiz (DiSiD) commented

Hi Sébastien, I meant "JSON data binding process following the same process of Validation, Data Binding, and Type Conversion than HTTP forms" in spite of to use the Jackson2 data binding, validation and conversion process.

By doing that, a web application hasn't to define Type Conversion, Data Binding and Validation processes two times.

I think this isn't the right issue to comment about this theme, Sébastien could you point me where to report this improvement?

Thanks

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 2, 2015

Sébastien Deleuze commented

Hi Enrique, could your request be related (at least partially) to #11715? I closed it as won't fix last year, but feel free to add a comment in this issue after reading the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.