Ok, first things first: these lines
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.setSerializationInclusion(Include.NON_EMPTY);
would simply result in second one taking effect: there is no way to
combine settings, there is simply one default level.
Second: with jackson 2.9, you can separately specify filtering both
for Container (List) and contents within.
You would get better results with
mapper.setDefaultPropertyInclusion(JsonInclude.ValueOf.construct(Include.NON_EMPTY,
Include.NON_EMPTY));
since that would first check elements for filtering (i.e. leave out
any that are empty), and taking this into account,
see if container might not have any non-empty elements, and be empty.
(if only container was checked it would see content elements and
decide container is non empty).
So far so good: in theory you could get nested case to work.
Unfortunately there is no concept of empty POJOs -- only Collections,
arrays, referential types (Optional) and some
scalar have this filtering mechanism available -- at least not without
custom handlers. This is because checking is done at Java Object
level,
and not at json token level (if it was latter determination could be
done in generic fashion).
But you could register custom serializer for `Student`, and override
its "isEmpty(SerializerProvider, T)", and this should work.
Question there is whether you want to do that, it's quite a bit of
work. It would be possible to use "BeanSerializerModifier", get
hold of standard BeanSerializer, and wrap that (in fact,
StdDelegatingSerializer does about this), and only override
"isEmpty()" implementation.
So, there are no settings that allow you to achieve this declaratively
that I know. There are ways you can build something to do it.
-+ Tatu +-
> --
> 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
jackson-user...@googlegroups.com.
> To post to this group, send email to
jackso...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.