Spring Boot: Json Response is not Mapping to Entity

Zeusox :

I am trying to map this Json response I consume through a secured RESTful API; however, the mapping is for some reason not happening correctly as I keep getting a NULL response instead of populated object.

This is my entity:

@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;
    }
}

This is my service method:

   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;
   }

This is my Controller Method:

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

The issue was with what my methods were returning. They both have to return a ResponseEntity of type Order as in:

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;
}

And my Controller to:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=359313&siteId=1