Answer the question
In order to leave comments, you need to log in
Is it right to create many POJO classes to generate json response?
Hello.
Requests for data are coming from the client, and they must be returned as Json.
json example:
{
"root" : {
"name1" : {
"name1_1" : {
"field1" : 10,
"field2" : 20
},
"name1_2" : {
"field1" : 30,
"field2" : 40
}
},
"name2" : {
"name2_1" : {
"obj1" : {
"field3" : 50.01,
"field4" : 60.02,
"field5" : 70.03
},
"obj2" : {
"field3" : 80.80,
"field4" : 90.90,
"field5" : 100.90
},
"obj3" : {
"field3" : 110,
"field4" : 120,
"field5" : 130
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Yes, it is normal. Your application has an api that contains the entities you work with and return to the client (and the internal representation and external model may differ).
To get rid of the boilerplate with getters, setters and more, use lombok
/**
* аннотация @Data добавит в байткод методы
* getString, setString,
* getAnotherString, setAnotherString,
* equals, hashcode, toString
*/
@Data
public class App {
private String string;
private String anotherString;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question