The json that I have to send looks like this:
{
"id": 0,
"height": 0,
"name": "string",
"list": [
{
"klk": 0,
"name": "string",
"subject": 0,
"subjectType": "string",
"target": 0
}
],
"type": "string",
"group": 0,
"width": 0
}
class First {
private Long id;
private Integer height;
private Integer width;
private String name;
private String type;
private Long group;
private List<Second> list;
}
class Second {
private Long klk;
private String name;
private String subjectType;
private Long subject;
private Long target;
}
So basically I have a DTO that contains a list of DTOs. As you can see both DTOs have a lot of parameters.
How to pass the values to the service layer without passing 10 parameters (or the DTO itself)?
I need some ideas...
CodePudding user response:
Try to use getter and setter or use Jackson Annotations.
CodePudding user response:
You can pass it as List where Object can be any class type from the 10 class . And at service layer side use below implementation to identify type of class .
pseudo code
for()
{
if(list.get(i).getClass().equals(First.class))
{
logic for class first
}
else if(..)
//same way you can do it using if else or switch
}