-
Notifications
You must be signed in to change notification settings - Fork 136
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
Use Bean Validation (JSR 303) annotations for resolving JSON schema validation constraints #32
Conversation
First of all, thank you for this contribution! This is a very interesting idea, and seems useful. |
Sure, I'm ready to discuss this on the mailing list. Just want to say, that Bean Validation annotations is the most standardized and logical way of validation constraints resolving for JSON schema. So I think it will not be a problem to add a small standard java dependency. |
@cponomaryov I agree -- and as I said, I think this is a great idea. A brief discussion will also have the benefit of making more devs aware of this new feature; one challenge I have seen has been that there are so many new things that it is easy to miss good improvements. I also think this could be really nice for services, since Bean Validation annotations are used by things like DropWizard to validate configurations. |
Wondering where is this going. With 2.4 I am thinking that this could be done using SchemaFactoryWrapper as custom properties like like the HyperJsonSchema. Seems like this needs a rewrite. |
Makes sense. Give me a couple of days to rewrite this. |
I have refactored this to use SchemaFactoryWrapper. |
Unfortunately since this did not make it in 2.4, I need to wait until we create 2.4 branch, and then merge this for 2.5. But I hope this is not a long delay. |
Some branch should be fine for me.
|
Look forward to seeing this in jackson. Have been trying to validate jsonschema2pojo beans with hibernate, cryptic errors and ugly maven dependency exclusions required |
Any chance this is merged soon? I am realy looking forward to this! |
@cponomaryov Ok, before merging, one thing I need to make sure is to have the filled Contributor License Agreement (CLA). If I haven't yet asked for one (I don't think I have a copy, looking at ones I have?), could you get this one: https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf and print, sign, scan and email to |
This is good, but we really need a way to handle all of the other constraints in JSON Schema. This handles: It does not handle: Hibernate could handle "required" with @NotNull and "pattern" with @pattern. The rest of them would require some custom annotations. Would love to hear your thoughts on doing this in some kind of standards-compliant way. I wonder if it would make sense to create a bunch of new Jackson-specific annotations that map to all of the JSON Schema constraints? (There's got to be a better way, but I haven't found it.) |
@ccleve Good point. I think there are two starting points here:
and I think there is validity to both. Doing (1) often gets you to first part of 80/20. I don't have strong opinion on
So I think that perhaps these could/should be piped through existing method of Eventually we may also bump into somewhat deeper problem with JSON Schema -- it focuses a lot on kinds of things JSON might express, but not enough (IMO) on how object models of programming languages (like Java) work. I think that former is much less important than latter; and focus with JSON Schema is bit sub-optimal. But I hope there are many things we can improve before hitting the limits. |
This should also handle constraint composition -- constraints that are defined purely by the composition of other constraints. If this was supported, any constraints from other libraries that are defined purely by composition, such as NotEmpty in Hibernate Validator, would be automatically supported without having any dependencies on those libraries. |
it would be great if we had the basic part out of the door, then the community (me included) will build upon it and add more features or is the goal to do big bang and provide all futures right from the start. |
@cponomaryov @Vad1mo At this point I am just waiting for CLA, as per my earlier comment. After that I can merge this PR. |
The two sides: Model side Bean Validation and Client side JSON validation will not converge until a common set of specifications are set forth i.e. Bean validation and JSON schema are married into one specifications. I would personally like JSON validation move towards something like http://annotatorjs.org/ and use Annotations and let the Annotator plugins do its thing. FYI - AngularJS community is moving towards annotation for dependency injections etc albeit for different things. Having said all these things I will just get to the following idea (which I am using at my work):- Let the jackson module extract out all annotations on a Bean and its properties into JSON schema as additional properties. (This is where a standard Annotation property is worth while in JSON schema but for now this could be "additionalProperties": [] schema property) Let this module be configurable to include global filters - excludes, includes by package patterns. Such generic solution will eliminate the need do anything for JSR 303 or any future versions. |
Ok, enough procrastination, will proceed with merge. |
Use Bean Validation (JSR 303) annotations for resolving JSON schema validation constraints
very good! |
Just my two cents: |
Use Bean Validation (JSR 303) annotations:
@Size
for settingArraySchema
'sminItems
andmaxItems
propertiesStringSchema
'sminLength
andmaxLength
properties@Min
and@DecimalMin
for settingNumberSchema
'sminimum
property@Max
and@DecimalMax
for settingNumberSchema
'smaximum
property