-
Notifications
You must be signed in to change notification settings - Fork 79
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
Support for default values #23
Comments
This could work easily with Strings, esp. since Also note that Jackson can not yet rely on Jackson 8. This will change with Jackson 3.0, which is in relatively near future, so it's just a short-term obstacle for default methods. Aside from these I like the idea. |
Come to think of this, there's now @JsonProperty(defaultValue="default value as string") which could be used for a few types; and primitives for sure (and Strings obviously). |
@cowtowncoder yes, it would be nice to use that. I can see from the comment of
|
Right, wiring exists such that this value is easily accessible to (de)serializers via I don't think I have time to work on this before 2.9.0, but then again adding support would not be breaking change and could perhaps go in 2.9.x if anyone has time to work on this. |
Some languages provide much richer options for providing default values than Java annotations use (eg, Scala default parameter values). Also, I wouldn't be surprised if a JEP appears that adds default value parameters to Java - it seems Java is adopting Scala features at an accelerating pace these days. I think it would be great if Jackson could be prepared for this. One thing though, the current |
True, although it may not be necessary to use this mechanism for figuring out default values that come from other metadata. |
Also: this issue probably belongs to |
Why was this issue closed? It seems it's still not possible to assign a default value when deserializing with Jackson latest version, not even when using |
@Ghilteras it was mostly closed because actual support for using annotated default values would be in databind: FasterXML/jackson-databind#618 and since no one has had time or interest to work on other parts here. If you feel like you would like to work on something, feel free to reopen. |
@cowtowncoder I'm not sure I understand the reference to another closed issue in a different repo which was closed 3 years ago. The issue should be opened somewhere as a feature request if nobody ended up addressing it, either here or on jackson-databind, wherever you guys feel more comfortable tracking it. |
@Ghilteras what closed issue? Now I am confused. |
Besides this stackoverflow question, I couldn't really find any information related to this topic but it would be nice to extend the support of default values in Jackson, particularly in the context of the MrBean module.
One option could be using annotations:
Another option could be using Java 8 default methods:
Currently, there are two main limitation I see for MrBean:
The text was updated successfully, but these errors were encountered: