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 support for basic "is-required" checks on deserialization using @JsonProperty(required=true) #230

Open
cowtowncoder opened this issue May 23, 2013 · 9 comments
Labels
most-wanted Tag to indicate that there is heavy user +1'ing action

Comments

@cowtowncoder
Copy link
Member

(note: moved from https://jira.codehaus.org/browse/JACKSON-767)


As per title, although full validation of values is out-of-scope for Jackson, very basic "must be included in JSON" checks may fall in 80/20 line of things. Especially since we already have annotation to use.

The trick here is implementation; from two distinct parts:

  1. This requires handling and retaining of extra state (what has been included) during deserialization by BeanDeserializer, and passing it; not trivial to do with current code.
  2. Due to combinatorial explosion by features, efficiency, we need to be careful not to add Yet Another combination of things to tackle, requiring adding yet more similar (but not identical) methods
@theon
Copy link

theon commented May 25, 2013

This would be really useful for us for generating JSON Schema. In JSON Schema properties are optional by default and need to be explicitly marked as required.

See FasterXML/jackson-module-scala#80

@cowtowncoder
Copy link
Member Author

As far as I know, this is already being used for schema generation. In fact, the only real use for the property.
This should at least be the case for the external json schema module.

@theon
Copy link

theon commented May 28, 2013

You are of course correct 😃 I've tested this with both the external json schema module and the jackson-databind schema generation and both respect the required property in the @JsonProperty annotation.

@cowtowncoder
Copy link
Member Author

Some good news: #781 -- which adds support for required-ness for Creator methods -- has been implemented, and will be in 2.6. I hope it also helps figure out eventual general implementation for required.
And perhaps even support for default values, in distant future.

@operatiay
Copy link

2.6.0-rc4 doesn't work for me.

I've added
objectMapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true);
without any effect.

@walec51
Copy link

walec51 commented Aug 27, 2015

Did you use this annotation on a constructor method ?
It does not work on class attributes. That's why this issue is still open.

@operatiay
Copy link

thank you @walec51 . Constructor annotation did work for me.

@utsengar
Copy link

Do we have an update on this for class attributes? Been 1yr since last update.

@cowtowncoder
Copy link
Member Author

@utkarsh2012 If there is work we will update the issue. There is not much point in asking for things when there is no indication anything has changed. If you want to ask questions, in general, mailing list is a better place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
most-wanted Tag to indicate that there is heavy user +1'ing action
Projects
None yet
Development

No branches or pull requests

5 participants