Skip to content
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

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

Open
Riciardos opened this issue Jul 16, 2018 · 1 comment
Open

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

Riciardos opened this issue Jul 16, 2018 · 1 comment

Comments

@Riciardos
Copy link

Riciardos commented Jul 16, 2018

I've created a little 'sensitive data hiding' class that's basically a wrapper class with a custom toString() 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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants