MultiValueMap引起的问题application / json; charset = UTF-8不支持

问题描述 投票:0回答:1
class A {

    @NotNull
    @NotEmpty
    String name;

    B b;

    //setters and getters
}

class B {

    MultiValueMap<String, String> keyMultiValues;

    //setters and getters
}


@RestController
class MyController {

    @PostMapping(value="/test", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public String doSomething(@RequestBody @Valid A a){       
                 //some business logic

    }

}

由于在B类中使用MultiValueMap而导致出现以下错误[org.springframework.web.HttpMediaTypeNotSupportedException:内容类型'application / json; charset = UTF-8'不支持]

任何想法,如何解决上述问题?

spring spring-boot spring-mvc spring-restcontroller spring-rest
1个回答
1
投票

请根据需要向数据类的实现更改接口,以向解析器精确显示他应使用的实现。在这种情况下,您可以使用例如LinkedMultiValueMap。

© www.soinside.com 2019 - 2024. All rights reserved.