Let's say I an output class that will be converted to JSON:
StudentSummary.java
public class StudentSummary {
private StudentList studentList;
// getters setters
}
and
StudentList.java
public class StudentList {
private int numberOfStudents;
private int totalExpenditures;
private List<Student> students;
// getters setters
}
After making a service call, I get this JSON output:
{
"studentSummary": {
"studentList": {
"numberOfStudents": 500,
"totalExpenditures": 250000,
"students": [ /* students listed */ ]
}
}
I want to exclude from JSON the studentList
in the StudentSummary
class:
{
"studentSummary": {
"studentList": {
"numberOfStudents": 500,
"totalExpenditures": 250000
}
}
}
I've tried using (in the StudentSummary output class) @JsonIgnore
and @JsonProperties
, by specifying to only exclude "studentList.students"
, but that doesn't do anything.
EDIT: Further clarification, for why I couldn't do the changes inside the StudentList class, it's because it is used by another service and the service with StudentSummary class is of a different service, so I can only make the changes inside the latter class, without modifying the previous service.