You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It works fine when there is a value, but when the value is empty, it serializes it to null. I'd like to have a way to customize what happens when the value is empty, maybe passing a callback when creating the Jdk8Module instance.
For my current use case, I 'd like to throw an exception that represents a 404 error, but maybe in other applications it would be necessary to use another object instance representing the missing data.
The text was updated successfully, but these errors were encountered:
I guess the first thing would be to understand why you think alternate handling is needed: why doesn't method itsel fail if you want to throw an exception? What is the problem in serializing it as null that you are trying to solve?
Or if you do not want to serialize such value at all, JsonInclude.NON_ABSENT (or just NON_EMPTY which cover case of absent) can be used to configure behavior.
Beyond this it could perhaps be possible to allow alternate configuration of default Optional serializer this module provides, and then allowing passing differently configured instance.
But I want to first understand the problem to solve, before considering solutions.
My intention was not only for this use case, but also for other use cases where the developer might want to return something else, like a default value or dummy object instead of null.
But after thinking more deeply, I think all these use cases can be handled by the application code with custom getters when serializing the object and should not be responsibility of the library.
I have this simple use case using Spring Boot serializing a
java.util.Optional
.It works fine when there is a value, but when the value is empty, it serializes it to
null
. I'd like to have a way to customize what happens when the value is empty, maybe passing a callback when creating theJdk8Module
instance.For my current use case, I 'd like to throw an exception that represents a 404 error, but maybe in other applications it would be necessary to use another object instance representing the missing data.
The text was updated successfully, but these errors were encountered: