Apply '@Valid' to properties with "existingJavaType"#1781
Apply '@Valid' to properties with "existingJavaType"#1781unkish wants to merge 4 commits intojoelittlejohn:masterfrom
Conversation
|
Idea of applying This little POC is for the case if a non elegant approach could be considered for properties having |
|
Looks good to me. I think we should merge this in 1.3.4 to avoid losing @Valid on fields that use existingJavaType. |
...n-tests/src/test/java/org/jsonschema2pojo/integration/config/IncludeJsr303AnnotationsIT.java
Outdated
Show resolved
Hide resolved
...hema2pojo-integration-tests/src/test/resources/schema/jsr303/minAndMaxItemsExistingType.json
Outdated
Show resolved
Hide resolved
...hema2pojo-integration-tests/src/test/resources/schema/jsr303/existingJavaTypeProperties.json
Show resolved
Hide resolved
|
Unrelated to this commit: 1.6 - perhaps that should be changed to 8
|
|
It looks like there's one cornercase. {
"type": "object",
"javaType": "com.example.ExistingJavaTypeProperties",
"additionalProperties": false,
"properties": {
"itemOfExistingClassFqcn": {
"type": "object",
"existingJavaType": "com.example.ClassWithSizeAnnotation"
},
"itemOfExistingClass": {
"type": "object",
"existingJavaType": "ClassWithSizeAnnotation"
}
}
}Generates a code that is compiling (note the placement of @JsonProperty("itemOfExistingClassFqcn")
private com.example.@Valid ClassWithSizeAnnotation itemOfExistingClassFqcn;
@JsonProperty("itemOfExistingClass")
private @Valid ClassWithSizeAnnotation itemOfExistingClass;but fails validation: instance = createInstanceWithPropertyValue(clazz, "itemOfExistingClassFqcn", new ClassWithSizeAnnotation());
assertNumberOfConstraintViolationsOn(instance, is(1));Prefix is added in if (!isImported(f, rawType) && !prefix.isEmpty()) {
f.p(prefix);
}Since generated type and I have not yet figured out how to fix this. |
|
Is the problem just aesthetic @unkish? i.e. |
Validation is not working as |
* removed unused imports
|
@joelittlejohn I haven't been able to think of any better solution than either
|
|
@unkish Sorry, I'm being dense here. Could you add a failing test? I don't see why this is a problem: @JsonProperty("itemOfExistingClassFqcn")
private com.example.@Valid ClassWithSizeAnnotation itemOfExistingClassFqcn;
@JsonProperty("itemOfExistingClass")
private @Valid ClassWithSizeAnnotation itemOfExistingClass;and I don't understand why it leads to this:
The annotation placement on itemOfExistingClassFqcn looks correct to me. Yes, it's using a fully qualified name for the class even though it does not have to, but the annotation is in the right place, isn't it? If you add a failing test here I will see if I can think of a way to fix it. |
|
@unkish Never mind, I have created a failing test now based on the schema you provided. Now to fixing... |
|
My understanding is that in case of |
|
Two options on my table atm:
@joelittlejohn when you have some spare time, I would appreciate if you could have a look and share your thoughts on proposed solutions or any alternative approaches that might solve the issue. |
No description provided.