Skip to content

resolveRequestBody algorithm does not take into account ConversionService when determining if binding is possible [SPR-6729] #11395

Closed

Description

@spring-projects-issues

Keith Donald opened SPR-6729 and commented

I noticed this when using @RequestBody on an Account JavaBean @Controller parameter, when the ContentType of my POST /accounts request was "application/x-www-form-urlencoded". In this case, the resolved FormHttpMessageConverter is only capable of reading a MultiValueMap, not an Account, so I get a 415 back due to a HttpMediaTypeNotSupportedException. However, the ConversionService configured with Spring MVC may be capable of mapping a MultiValueMap to a JavaBean, but it is never queried inside resolveRequestBody of AnnotationMethodHandlerAdapter. If the ConversionService is capable of such a mapping, should it be invoked to allow the Account binding to succeed? Or should it be the sole responsibility of the MessageConverter to determine if binding is possible?


Affects: 3.0 GA

Issue Links:

1 votes, 1 watchers

Activity

  1. spring-projects-issues commented on Jan 20, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Keith Donald commented

    Given the relationship with #11397, I would tend to think whether the ConversionService was used or not would be an implementation detail of the MessageConverter. Something to think about.

  2. spring-projects-issues commented on Feb 17, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Bryan Kelly commented

    Is there currently a work around to this issue when using 3.0.5 of spring-web?

  3. spring-projects-issues commented on Jun 7, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Turning a MultiValueMap into a typed object seems more like data binding. You could do:

    public void update(@RequestBody MultiValueMap<String, String> map) {
      Account account = new Account();
      WebDataBinder binder = new WebDataBinder(account);
      binder.bind(map.toSingleValueMap();
      // ...
    }

    If you have this often enough, consider creating your own annotation and implementing a custom HandlerMethodArgumentResolver probably extending from AbstractMessageConverterMethodProcessor.

  4. spring-projects-issues commented on Jun 8, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Better yet, just use @ModelAttribute! (see #13063)

  5. added
    status: declined
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions