FasterXML / jackson-future-ideas

Repository for SOLE PURPOSE of issue tracker and Wiki for NEW IDEAS. Please: NO BUG REPORTS.
18 stars 6 forks source link

Add overridable isFieldNull() method to JsonSerializer<T> #27

Open Riciardos opened 6 years ago

Riciardos commented 6 years ago

I've created a little 'sensitive data hiding' class that's basically a wrapper class with a customtoString() method.

To make this work with existing classes I registered a custom serialiser that unpacks the value and passes it on. This works great, and if the field is null, the Include.NON_NULL works great as well.

However, when the value inside the wrapper is null, it doesn't get picked up and it still serialises to "fieldname":null. To get around this I have to implement the isEmpty() method in the custom serialiser and use Include.NON_EMPTY on the class that uses the wrapper. This is not bad, but maybe it would be nice to either be able to specify when a field can be considered null with a isFieldNull() or something similar, so you can keep on using NON_NULL and not accidentally remove other fields for being an empty string for example.

I would understand if you'd rather keep it this way to not bloat the interface, but I thought I'd share the idea.

cowtowncoder commented 6 years ago

First of all, thank you for suggesting the idea! I am aware that null handling is (and has been) a challenging part; and further with planning of Jackson 3.x, time is right for possible additions.

I will have to think about this (or something similar to address use case) in context of all changes, as well as in how serializers interact. But it is a good data point, and reminder that improvements would be good in this area.