Skip to content

LoggingEventCompositeJsonEncoder - how omit nestedField if empty? #762

Answered by brenuart
dtanner asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Dan,

There is unfortunately no built-in way to accomplish what you describe. The PatternJsonProvider is the only provider with the ability to omit empty fields (cfr omitEmptyField property). We have plan to make this feature available to all providers and are working on it... expect this feature to be included in one of the up coming releases.

In the meantime you can decorate the Jackson JsonGenerator yourself to make it filter empty fields. The following sample JsonGeneratorDecorator should do the job:

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.filter.FilteringGeneratorDelegate;
import com.fasterxml.jackson.core.filter.TokenFilter;
import com.fa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dtanner
Comment options

Answer selected by dtanner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants