Replies: 2 comments 3 replies
-
So what you are suggesting is global configuration that works like... if (enableDiscardOnValue && value.equals(configuredValue)) {
// do not serialize
} ... this? |
Beta Was this translation helpful? Give feedback.
-
There is a technical reason why adding such method in But... Maybe consider existing https://cowtowncoder.medium.com/jackson-tips-filtering-with-jsoninclude-27f08979514c that works today. |
Beta Was this translation helpful? Give feedback.
-
It could be very handy to have a method to discard some fields by value.
In my use case, I use for integers the value Integer.MIN_VALUE to discard the field. I can achieve this with annotations, but in my project I want this feature for all integers and I have a lot, I can forget the annotations for an integer... So this method could centralize all this stuff and will be very safe.
Just modify JsonSerializer to add this method
public boolean discard(SerializerProvider provider, T value) {
return false;
}
And call it on BeanPropertyWriter, method serializeFields before starting to serialize.
Beta Was this translation helpful? Give feedback.
All reactions