小编Adr*_*ano的帖子

使用 Spring Cloud Open Feign 获取 JSON 中的对象列表

我有一个应用程序,当我调用其服务之一时,它会返回以下 JSON:

{
     "suppliers": [
         {
             "name": "Joaquim",
             "email": "joaquim@email.com",
         },
     {
             "name": "Manoel",
             "email": "manoel@email.com",
         }
     ]
}
Run Code Online (Sandbox Code Playgroud)

为了访问这些数据,我使用具有以下方法的 Feign 客户端:

@FeignClient(name = "suppliersClient", url = "www.url-example.com.br")
// ...
List<SuppliersDTO> searchSuppliers(@RequestParam("city") String city);
Run Code Online (Sandbox Code Playgroud)

根据城市的不同,它会返回供应商列表。这段代码是一个简单的例子,向你解释我想要做什么。

除了和之外,我的 DTO Supplys 类还具有name和字段。emailgetterssetters

public class SuppliersDTO {

     String name;
     String email;

     // GETTERS AND SETTERS
Run Code Online (Sandbox Code Playgroud)

使用这样的代码,当使用 Feign 客户端时,我收到 500 内部服务器错误,其中包含以下信息:

"Error while extracting response for type [java.util.List<com.domain.store.dto.SuppliersDTO>] and content type [application/json;charset=utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc spring-boot spring-cloud spring-cloud-feign

5
推荐指数
1
解决办法
6195
查看次数