Closed Viserius closed 5 months ago
Managed to fix this and update the dependency for JDK 17 in https://github.com/Viserius/krasa-jaxb-tools
Hi Viserius, I have tried to replicate your error on my own version without success so I have pushed the latest changes (still 2 years old!) to github, could you please check if the problem is still there? In case it should be, could you send me the offending XSD so I can create a test case for it and fix it?
Thank you Francesco Illuminati
On Sat, Jan 20, 2024 at 3:02 PM Viserius @.***> wrote:
Managed to fix this and update the dependency for JDK 17 in https://github.com/Viserius/krasa-jaxb-tools
— Reply to this email directly, view it on GitHub https://github.com/fillumina/krasa-jaxb-tools/issues/10#issuecomment-1902102927, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMP5VQ7OHNFLZASYJOW6L3YPPE7VAVCNFSM6AAAAABCCA5GFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBSGEYDEOJSG4 . You are receiving this because you were mentioned.Message ID: @.***>
Hello @fillumina,
It is a bit difficult for me to reproduce it since I lost my test set-up, but this is the XSD causing the double @Valid annotations, which I believe is caused by first applying the @Valid through the more secure method that checks if it not exists already, and the 2nd is added by the
if (property.isCollection()) {
addValidAnnotation(propertyName, classOutline.implClass.name(), field);
}
block.
Here is a stripped XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.foo.nl/bar" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sci="http://www.foo.nl/bar" version="28.0">
<xs:element name="message" type="sci:redacted3"/>
<xs:complexType name="redacted3">
<xs:sequence>
<xs:choice>
<xs:element name="redacted2" type="sci:redacted"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="redacted">
<xs:sequence>
<xs:element name="redacted6" type="sci:redacted4" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="redacted4">
<xs:sequence>
<xs:element name="redacted7" type="sci:redacted5" minOccurs="0" maxOccurs="200" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="redacted5">
</xs:complexType>
</xs:schema>
Resulting in the following Redacted4.java-file:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "redacted4", propOrder = {
"redacted7"
})
public class Redacted4 {
@Valid
@Size(min = 0, max = 200)
@Valid
protected List<Redacted5> redacted7;
public List<Redacted5> getRedacted7() {
if (redacted7 == null) {
redacted7 = new ArrayList<Redacted5>();
}
return this.redacted7;
}
}
I have tested your XSD and it's working fine. The new commit just included your XSD and the test. I am planning to release a new 2.3 version soon after a bit of cleaning up to solve some accumulated technical debt. Sorry to have waited for soooo long to update the library (with code I had since 2 years ago!).
@fillumina Glad to hear the tests are running on the XSD! To be fair, it was quite difficult to reproduce this issue last time. I encountered this problem after updating the dependency in my project to v2.2 in combination with cxf-codegen-plugin and a wsdl containing the given XSD. While working on a fix, I checkout out this repo on the latest release version (2.2), added the XSD to one of the tests, and encountered the same issue when running the tests. After patching it, of course I threw away all test code, and now I am unable to reproduce it inside the test code and entering the buggy xsd now gives a good output on v2.2 while I still see the buggy class when called using the cxf plugin.
Anyway, I thank you for your time and will test v2.3 or the last version on master when I get to it next week, in combination with the complete xsd, wsdl and cxf plugin.
@fillumina I just compiled the master-branch and tried to test this on our project to see if there are still duplicate @Valid-annotations being generated. However, it seems the latest master-version with the new parsing arguments results in the following exception:
[WARNING] Exception in thread "main" org.apache.cxf.tools.common.ToolException: XJC reported 'BadCommandLineException' for -xjc argument:-extension -XJsr303Annotations -XJsr303Annotations:generateNotNullAnnotations=true -XJsr303Annotations:notNullAnnotationsCustomMessages=true -XJsr303Annotations:JSR_349=false -XJsr303Annotations:verbose=false -XJsr303Annotations:validationAnnotations=jakarta -XJsr303Annotations -XJsr303Annotations:generateNotNullAnnotations=true -XJsr303Annotations:notNullAnnotationsCustomMessages=true -XJsr303Annotations:JSR_349=false -XJsr303Annotations:verbose=false -XJsr303Annotations:validationAnnotations=jakarta
[WARNING]
[WARNING] Available plugin options:
[WARNING]
[WARNING] at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:426)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:711)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:259)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:156)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:402)
[WARNING] at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
[WARNING] at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
[WARNING] at org.apache.cxf.maven_plugin.wsdl2java.ForkOnceWSDL2Java.main(ForkOnceWSDL2Java.java:51)
[WARNING] Caused by: com.sun.tools.xjc.BadCommandLineException: unrecognized parameter -XJsr303Annotations
[WARNING] at com.sun.tools.xjc.Options.parseArguments(Options.java:856)
[WARNING] at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:410)
[WARNING] ... 8 more
This error does not occur on version v2.2, so I suspect you changed the way the arguments are passed but forgot to update the README. Also note that these changes do seem to be a breaking change
I have tested your XSD and it's working fine. The new commit just included your XSD and the test. I am planning to release a new 2.3 version soon after a bit of cleaning up to solve some accumulated technical debt. Sorry to have waited for soooo long to update the library (with code I had since 2 years ago!).
@fillumina Any update for the 2.3 version? Along with this issue, I also have the other issue mentioned here: https://github.com/fillumina/krasa-jaxb-tools/issues/8, not sure if they have the same root cause...
I'm working on it. Should be released soon. Sorry for the delay.
On Mon, Apr 22, 2024, 12:51 Huy Lê @.***> wrote:
I have tested your XSD and it's working fine. The new commit just included your XSD and the test. I am planning to release a new 2.3 version soon after a bit of cleaning up to solve some accumulated technical debt. Sorry to have waited for soooo long to update the library (with code I had since 2 years ago!).
@fillumina https://github.com/fillumina Any update for the 2.3 version? I have the same issue as described here: #8 https://github.com/fillumina/krasa-jaxb-tools/issues/8, not sure if they have the same root cause...
— Reply to this email directly, view it on GitHub https://github.com/fillumina/krasa-jaxb-tools/issues/10#issuecomment-2069084210, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMP5VTIUFU5ZMPTC75FFYTY6TTU7AVCNFSM6AAAAABCCA5GFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRZGA4DIMRRGA . You are receiving this because you were mentioned.Message ID: @.***>
Ok the new version 2.3 is out and should have addressed this problem. Could you please check? Thanks
The new refactored code should have addressed the duplicated annotation problem: I cannot reproduce it so a close the issue. Feel free to reopen it in case the problem should present again.
Hello @fillumina ,
After upgrading from 2.0 tot 2.2, I see the output of my generated Java class is as follows:
instead of
Since the @Valid annotation cannot be applied twice, this causes an exception during compilation.
jakarta.validation.Valid is not a repeatable annotation type
.After inserting my own XSD into one of your tests, I do NOT get the duplicate @Valid annotation, leading me to believe it is not due to an error in the XSD, but rather the change you made by inserting the following lines in version 2.2.
Note that it does not include a check whether the @Valid annotation already exists. Do you have any idea on how to solve this?