-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NestedJsonProvider: unable to omit empty nested field #764
Comments
As proposed in this discussion, an option is to decorate the JsonGenerator to make it filter empty fields. This option would be controlled by a new Most JsonProvider already omit their fields when they are empty and this behaviour is not configurable (cannot be disabled). Adding a new Instead of adding this feature to the CompositeJsonEncoder we could also limit it to the NestedJsonProvider. In this case the semantic must be clarified:
My feeling is when people want to filter out empty properties, they probably want it everywhere and not limited to only a few properties. Adding a global option affecting all properties would be very convenient and easy to understand. I would also enable this option by default and make sure all providers comply to it (i.e. make them output a null value instead of omitting their properties as they do currently if this new property is set to false). @philsttr What's your opinion? |
Hmm. Brainstorming here... What about having a global Maybe something like this:
The null/unset values mean behave exactly as they do today. And since the default is null/unset, the behavior is fully backwards compatible with how things work today. When a provider is contributing to the generator,
Not sure how easy that would be to implement. The providers would need to be able to change the "state" of the token filter before/after the provider contributes to the generator. My main reasoning for proposing the above is to be able to keep backwards compatibility, while also adding cool new features. Without the null/unset option, and just providing a true/false option, backwards compatibility is broken no matter if the default value is true or false, since neither represents the current behavior. And there would be no way to "revert" to the current behavior. Alternatively, just implementing a new |
As a consumer,
would work fine for me. In my normal configuration use case, I'm only adding a single nestedField, so config duplication isn't a concern. |
Most JsonProviders omit writing their field(s) if their value is null (absent). This is however not the case for the NestedJsonProvider. Consider the following configuration:
This configuration produces a JSON similar to the following:
However when not MDC keys are present or if none matches the include pattern of the MDC json provider, the "nested" object becomes empty and the output looks as follows:
There is unfortunately no option to omit the nested object when it is empty similar to what is available to the PatternJsonProvider.
The text was updated successfully, but these errors were encountered: