Java 使用ParameteredTypeReference时找不到类型错误的(映射)键反序列化器
我正在从应用程序1发出一个Post请求,我有以下信息Java 使用ParameteredTypeReference时找不到类型错误的(映射)键反序列化器,java,json,spring,spring-boot,rest,Java,Json,Spring,Spring Boot,Rest,我正在从应用程序1发出一个Post请求,我有以下信息 UriComponents uriComponents = builder.uri(uri).path("/api/accounts").build(); ParameterizedTypeReference<Map<Account, Position>> responseType = new ParameterizedTypeReference<Map<Account, P
UriComponents uriComponents = builder.uri(uri).path("/api/accounts").build();
ParameterizedTypeReference<Map<Account, Position>> responseType = new ParameterizedTypeReference<Map<Account, Position>>(){};
RequestEntity request = RequestEntity
.post(uriComponents.toUri())
.accept(MediaType.APPLICATION_JSON)
.body(requestStuff);
ResponseEntity<Map<Account, Position>> response = restTemplate.exchange(request, responseType);
return response.getBody();
下面的代码在应用程序2中,这是post请求到达的位置,然后返回所需的地图
@PostMapping(value = "/api/accounts")
public ResponseEntity<Map<Account, Position>> getAccountPositions(@RequestBody String requestStuff){
return ResponseEntity.ok(fetchAccountPositions.execute(requestStuff));
}
app1和app2中的Account对象完全相同
请帮助我了解如何解决反序列化问题。您的api响应格式是什么?(json)还可以看看这里json需要将键设置为字符串,因此需要使用account.id作为映射的键。或者试试这个:你的api响应格式是什么?(json)还可以看看这里json需要将键设置为字符串,因此需要使用account.id作为映射的键。或者试试这个:
@PostMapping(value = "/api/accounts")
public ResponseEntity<Map<Account, Position>> getAccountPositions(@RequestBody String requestStuff){
return ResponseEntity.ok(fetchAccountPositions.execute(requestStuff));
}
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot find a (Map) Key deserializer for type [simple type, class com.package.Account]