Jackson ignore empty objects "{}" without custom serializer
I would like to serialize to JSON a POJO containing another POJO with empty values.
For example, given:
class School {
String name;
Room room;
}
class Room {
String name;
}
Room room = new Room();
School school = new School("name");
school.room = room;
After the serialisation it will look like that
{ "name": "name", "room": {}}
Is it possible to exclude the empty object if all the fields of the class are also empty? Ideally globally for every object without writing custom code.{}