休息 API 结束点

Rest API end Point

为什么我不能使用 TreeMap<String,String> 在@RequestParam 之后? 它在我使用

时有效
Map<String,String>

示例:

 @RequestMapping(value = "customers/new", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
        public ResponseEntity<String> createAuthorizationRole(
        @RequestParam TreeMap<String, String> hierarchy,
        @RequestHeader(name = "userid") String userid,
        @RequestHeader(name = "clientid") String clientid,
        @RequestHeader(name = "authorization") String authToken) {

        return new ResponseEntity<>("new Customer created", HttpStatus.OK);
    }

这是我看到的错误:

java.lang.IllegalStateException: argument type mismatch
HandlerMethod details: 
Controller [com.demo.customer.odr.pc.branchAuthorization.BranchAuthorizationController]
Method [public org.springframework.http.ResponseEntity<java.lang.String> com.walmart.replenishment.odr.pc.branchAuthorization.BranchAuthorizationController.createAuthorizationRole(java.util.TreeMap<java.lang.String, java.lang.String>,java.lang.String,java.lang.String,java.lang.String)]
Resolved arguments: 
[0] [type=java.util.LinkedHashMap] [value={country=US, division=1, department=17, category=9295, subcategory=21032, subclass=0, fineline=9379}]
[1] [type=java.lang.String] [value=office\r0sss]
[2] [type=java.lang.String] [value=05af7587-2209-49e3-9193-64828ad240b3]
[3] [type=java.lang.String] [value=dhfdrNGXU7j19DZb]

Jackson 在映射抽象类型Map 时使用LinkedHashMap 作为默认类型值。 您可以自定义您的 ObjectMapper,注册一个自定义模块。

ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("custom", Version.unknownVersion());
module.addAbstractTypeMapping(Map.class, TreeMap.class);
mapper.registerModule(module);