-
Notifications
You must be signed in to change notification settings - Fork 18
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
Preserve annotations during schema creation #32
Comments
Hi, it's always better to give a concrete example of what you're trying to achieve. As far as I understand, you want to start from an XSD schema that contains Java classes can currently only be generated from WSDL files which contain embedded XML Schemas, using the utility script
Next, run these commands (from the directory where you cloned the jaxb-facets repository). I'm assuming that you are running a Unix operating system (e.g., Mac OS, Linux) and that you have Apache Maven (
This will generate (among other files, which you can ignore), the following file:
Take a look at the file and you will find the desired XSD annotations:
Good luck, and let me know how it goes... :) |
Hi, thanks for your answer. What I would like is to be able to add any type of annotation to a field of a class when generating the .java files from the xsd. The schema files are actually generated from a proprietary description of a binary format, which should then be parsed and serialized with preon (https://github.com/preon/preon). So, for example, the original class with annotations would look like: public class FooTest {
@BoundNumber(size="16", byteOrder = BigEndian)
public int foo;
@BoundString
public String world = "Hello World!";
} The schema, including the annotations, could then be something along these lines: <xs:complexType name="fooTest">
<xs:sequence>
<xs:element name="foo" type="xs:int">
<xs:annotation>
<xs:jannotation type=BoundNumber>
<param name="size" type="xs:string" value="16"/>
<param name="byteOrder" value="java:org.codehaus.preon.buffer.ByteOrder.BigEndian"/>
<xs:jannotation/>
</xs:annotation>
</xs:element>
<xs:element name="world" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:jannotation type=BoundString/>
</xs:annotation>
</xs:sequence>
</xs:complexType> Additionally, I would also like to add annotations for JPA mappings for each field of a class. As there is no webservice involved, a WSDL would not make much sense it that case. In the meantime, I think I found what i was looking for: https://github.com/highsource/jaxb2-annotate-plugin It seems this xjc plugin allows to define arbitrary annotations on Classe/Types and Fields/Elements, by using the xsd:appinfo tag. I will try it and report back on success. Thank you a lot for your answer so far :) |
Thanks for your detailed answer. jaxb2-annotate-plugin seems to provide what you're looking for. Feel free to come back here if it doesn't, then we can try to work something out... Closing this for now. |
Hi,
as far as I understand, the JAXB-Annotations are used to control aspects of the schema creation, e.g. type mapping or namespace binding. Therefore, these kind of Java annotations are not stored in the schema, and will not be reconstructed when generating a Java class from the schema.
For my application, I would like to define some types in JAXB Scheme, and generate Java classes out of it, including third party annotations. Is there any way to store non-JAXB Java annotations in an JAXB Schema file, and have xjc create the classes accordingly?
The text was updated successfully, but these errors were encountered: