-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Default Values for Optionals Or Reject All Nulls #988
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
Comments
Definition of But the other case of allowing missing properties should handle default value for |
Hi, I understand that you are a Java developer and perhaps are not familiar with monads and optionals (apologies if that is condescending). However, an Option[T] is explicitly stating that the type is optional - part of the type's DNA is that there may be no value for it - and hence a missing constructor value means it should default to a value of None. It is explained in more detail here: FasterXML/jackson-module-scala#203 If an object has two properties - one is optional and one is not - the type system is expressing what is mandatory - the optional values. Is there any way to do this currently - if the value is missing throw an exception unless it is an Option? In the "other case" you mention, then it would not fail if a value was missing from a non-optional type and the value would default to null. Would you consider a pull request with a new deserialization option: "REJECT_ALL_NULL_VALUES" or are you completely against adding new functionality that helps to support Scala optionals? |
I've added a pull request to demonstrate another possible way of solving this problem without interfering with the fail on creator properties. Please let me know what you think: #990 I'm happy to put in more effort if you give me guidance. Thanks |
@NTCoding keep in mind Jackson knows nothing about Scala, and generally does not care. I hope to have a look at the proposal in near future, but I am bit backlogged due to major rewrite of type handling to resolve long-standing problems with generic type resolution (wrt type aliasing, mostly). |
Thanks for the feedback. I guess the code is open source so I can publish my own fork for now. |
Replaced with #1402, which I think would provide all the pieces needed. Scala module might need something additional (and definitely needs to support this); but from |
Hello,
I think your library is great but it doesn't quite work for one Scala use case. When there is a property of type Option I want it to set a default value of none even when FAIL_ON_MISSING_CREATOR properties is true.
I would like to do this conventionally without having to apply any annotations to the code. Could you give me advice on the best way to implement this and I will do the work and send a pull request.
Something in here seems sensible:
Perhaps a new service "defaultCreatorValueProvider" or similar?
If there is a better way, or even an existing way, please let me know.
Thanks
The text was updated successfully, but these errors were encountered: