Affects: org.springframework.boot:spring-boot-starter-web:2.5.3
Problem:
I have a requirement to output object values. All null values should be included, but nested object should be replaced by nulls if it's empty (consists from only null fields).
For instance, this is wrong answer
{
"name" : null,
"age" : null,
"objectGroup1" : {
"id" : null,
"name" : null
},
"objectGroup2" : null
}
This is correct answer, that I must respond with:
{
"name" : null,
"age" : null,
"objectGroup1" : null,
"objectGroup2" : null
}
objectGroup1 was set to null.
I tried to create a Value Filter but I realized that I can't mark certain objects as null if it is empty. I also tried to write recursive ResponseBodyAdvice, and it worked, it recursively set null for empty objects, but it looks a bit ugly.
I want somehow to be able to override non simple object serialization of any kind of class (for any DTO class) to be able to set nested objects as null if its "empty" inside.
Comment From: rstoyanchev
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.