Problem:

I'm using spring mvc.
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 the wrong answer:
{ "name" : null, "age" : null, "objectGroup1" : { "id" : null, "name" : 
null }, "objectGroup2" : null }

The correct answer, that I must respond with:
{ "name" : null, "age" : null, "objectGroup1" : null, "objectGroup2" : null 
}

objectGroup1 was set to null but it is not filtered out!

I tried to create a Value Filter but I realized that I can't mark certain 
objects as null if it is empty, there is just no way to keep the key not 
filtered out, separated to its value.
I also tried to write recursive ResponseBodyAdvice in spring, and it 
worked, it recursively set null for empty objects, but it looks a bit ugly.

I want somehow to be able to override object serialization of any kind of 
class (for any DTO class) to be able to set nested objects as null if its 
"empty" inside without having to write some recursive code on top of the 
whole jackson serialization process.

How can I do this in a most efficient way?

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/3e29d950-7b08-4385-a20c-6b8126c34c64n%40googlegroups.com.

Reply via email to