-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 @Valid on all collections, not just those with items type "object" #158
Comments
|
To elaborate further, the equivalent syntax in draft03 is a union type. jsonschema2pojo doesn't support types of this kind as they cannot accurately be described, in a general way, in Java's type system. This kind of highly dynamic schema is not a good fit for binding to static types and you may find Jackson's tree API more effective. |
Yeah we found a way to get around the anyOf .We many validate whether the objects are of types A, B or C but because the @Valid annotation the objects which of type A,B or C are not validated.Do you think the union type will take care of it ? |
try this: "items": {
"type" : "object",
"anyOf" : ... @Valid is only used when the items are of type By omitting a type to get java.lang.Object values you are basically hacking the system and causing it to use a fall-back type. This is why the @Valid rule wouldn't expect to accommodate this case. |
You need The reason I suggested you might also want to use |
So you are saying the "javaType":"java.lang.Object" will not generate the @Valid annotation ? "types" : {
"type": "array",
"minitems":0,
"items":
[
{ "$ref": "A.json" },
{ "$ref": "B.json" },
{ "$ref": "C.json" }
]
,
"required" : false
} Looking at the PropertyRule code I realize the type of the objects inside items must either be an object or an Array.The type of the A.json, B.json and C.json is an object |
Yes, exactly, adding This library doesn't support union types:
Sorry if I'm not making myself clear enough. Here's the exact code that I am suggesting you could use: "types" : {
"type": "array",
"minitems":0,
"items": {
"type" : "object",
"javaType" : "java.lang.Object"
},
"required" : false
} |
Thanks the last piece does work. But there is one last problem I am facing. |
I'm afraid there is no way to use this library by support union types and polymorphic deserialization. Your schema and types currently have no indication of how/when A, B anc C should be used, how could Jackson know which one to create? If you have data like this, I suggest it may be more appropriate to hand code these types. You should look into Jackson's polymorphic deserialization. You'll certainly need to add something to your data to indicate the java type that should be used (the documentation suggests using a property in the data called One simple solution you can use here is to merge A, B and C together (assuming this is possible). Of course your types would accept potentially invalid data. |
I have a list of objects which internally hold types of either A,B or C .It has been declared in the following fashion
This generates a Pojo without the @Valid object
Question is would it be possible to add @Valid annotation on the list ?
The text was updated successfully, but these errors were encountered: