Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ParameteredTypeReference时找不到类型错误的(映射)键反序列化器_Java_Json_Spring_Spring Boot_Rest - Fatal编程技术网

Java 使用ParameteredTypeReference时找不到类型错误的(映射)键反序列化器

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

我正在从应用程序1发出一个Post请求,我有以下信息

        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]