봄 부팅 : JSON 응답은 엔터티에 매핑되지 않은

Zeusox :

나는이 확보 편안하고 API를 통해 소비하는이 JSON 응답을지도하는 것을 시도하고있다; 그러나, 매핑은 내가 대신 인구 객체의 NULL 응답을 받고 계속 같은 몇 가지 이유가 제대로 안될입니다.

이것은 나의 실체이다 :

@JsonTypeName("order")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT ,use = JsonTypeInfo.Id.NAME)
public class Order {

    @JsonProperty("id")
    private long customerd;

    @JsonProperty("email")
    private String customeEmail;


    public long getCustomerd() {
        return customerd;
    }

    public void setCustomerd(long customerd) {
        this.customerd = customerd;
    }


    public String getCustomeEmail() {
        return customeEmail;
    }

    public void setCustomeEmail(String customeEmail) {
        this.customeEmail = customeEmail;
    }
}

이것은 내 서비스 방법입니다 :

   public Order orderDetails (@RequestBody Order order){

       String username = "username";
       String password = "password";
       HttpHeaders headers = new HttpHeaders();
       headers.setBasicAuth(username, password);

       // request url
       String url = "https://test.myshopify.com/admin/orders/2013413015655.json";

       RestTemplate restTemplate = new RestTemplate();

       HttpEntity request = new HttpEntity(headers);

        ResponseEntity<Order> response = restTemplate.exchange(
           url, HttpMethod.GET, request, Order.class);

       return order;
   }

이것은 내 컨트롤러 방법입니다 :

    @GetMapping("/orderdetails")
    @ResponseStatus(HttpStatus.FOUND)
    public Order getBasicAut(Order order){
        return basicAuth.orderDetails(order);
    }
Zeusox :

문제는 내 방법이 반환 된 것과이었다. 둘 다 같이 타입 주문의 ResponseEntity을 반환해야합니다 :

public ResponseEntity<Order> orderDetails (@RequestBody Order order){

   String username = "username";
   String password = "password";
   HttpHeaders headers = new HttpHeaders();
   headers.setBasicAuth(username, password);

   // request url
   String url = "https://test.myshopify.com/admin/orders/2013413015655.json";

   RestTemplate restTemplate = new RestTemplate();

   HttpEntity request = new HttpEntity(headers);

   ResponseEntity<Order> response = restTemplate.exchange(
           url, HttpMethod.GET, request, Order.class);


   return response;
}

그리고 내 컨트롤러 :

@GetMapping("/orderdetails")
@ResponseStatus(HttpStatus.FOUND)
public ResponseEntity<Order> getBasicAut(Order order){
    return basicAuth.orderDetails(order);
}

추천

출처http://43.154.161.224:23101/article/api/json?id=364299&siteId=1