0

Hi these is my model that inclues some simple field and a set of OrderModel.

public class ActiveRequsetModel {
 private Long id;
 private String applicatorDescription;
 private Customer customer;
 private Set<OrderModel> odersModel = new HashSet<>();
}

and this is my method in my controller

@RequestMapping(value = "/register-request", method = RequestMethod.POST, consumes = "application/json")
    @ResponseBody
    public ResponseEntity<String> registerActiveRequest(@RequestBody ActiveRequsetModel activeRequsetModel){

        customerService.registerActiveRequest(activeRequsetModel);

        return new ResponseEntity<>("Request registered.", HttpStatus.OK);
    }

and this is what I get from client side as you see it includes a applicatorDescription, customer object and a List of orderModel with key ordersModel.

{
    "applicatorDescription" : "quick please",
    "customer" : {
       "id" : 1
    },
"ordersModel" : 
[
    {
        "transfereeName" : "Alex",
        "address" : "home",
        "countOrSize" : 12.5,
        "derap" : 4,
        "description" : "descriptionnnnn",
        "kalite" : {
            "id" : 1
        },
        "product" : {
            "id" : 1
        }
    }
]

}

When I get request spring can bind customer and applicatorDescription, but It can't bind ordersModel. What should I do?

  • Make sure you don't make spelling mistakes: ActiveRequsetModel -> ActiveRequestModel, oderModel -> ordersModel – Jesper Mar 11 '19 at 12:00

1 Answers1

0

Your Model class is here:

public class ActiveRequsetModel {
 private Long id;
 private String applicatorDescription;
 private Customer customer;
 private Set<OrderModel> oderModel = new HashSet<>();
}

Change private Set<OrderModel> oderModel = new HashSet<>(); as

private List<OrderModel> oderModel

Also, OrderModel class should independent class. If OrderModel is an inner class then jacson cannot bind the request with class.

For more info visit this thread

Hope this will help you

Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87