This is possibly a duplicate of this question (Avoiding Compiler warnings on code generated by xjc) but since I am not very well versed in XJC/JAXB custom bindings idiosyncrasies, I'll presume I may have misunderstood the mentioned question.
My question seems simple enough - how can I add @SuppressWarnings("all")
annotation to generated JAXB class? We have 0 warning policy on our project and after JAXB generation step, we end up with 350+ warnings which are just terrible noise.
I would expect either a simple flag on the XJC or at least an easy way to provide such info but I cannot find any.
From what I've seen in my travels, people do one of these things:
Formerly, we dealt with this by shoving the XML-related code in a separate Eclipse project and then disabling the warnings/errors on the project. Now, as part of code consolidation/refactoring, we've reshuffled things around and no longer have that luxury.
Is there really no elegant solution for such a seemingly trivial problem? Any feedback/thoughts are greatly appreciated.
FWIW, our project uses Ant as build system.
You have to use this plugin : jaxb2-annotate-plugin
2 solutions :
1 - Modify your xsd and add this kind of block
<xsd:element name="foobar" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate>@java.lang.SuppressWarnings("all")</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
2 - Create a custom binding
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<annox:annotate target="class">@java.lang.SuppressWarnings("all")</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With