I have two Dto:
1) ObjectDto
{
"id":Integer,
"model": TypeDto
}
2) TypeDto
{
"id": String,
"description": String
}
In my controller java I have:
@RequestMapping(value = "/my/endpoint", method = RequestMethod.POST, produces = "application/json")
public void controllerMethod(@RequestBody ObjectDto reqDto) {
// something
}
And this is ObjectDto:
public class ObjectDto {
private Integer id;
private TypeDto model;
public ObjectDto(){}
// getter and setter
}
public class TypeDto {
private Integer id;
private String description;
public TypeDto(){}
public TypeDto(Integer id){
this.id = id;
if(id == 1){
t.description = "Id is " + id;
}else{
t.description = "nothing";
}
}
// getter and setter
}
If I received via POST Http call:
{
id:0,
model:1
}
How can I deserialize the object using the TypeDto correct constructor?
The result will be:
{
id:0,
model:{
"id":1,
"description":"Id is 1"
}
}