jaxb2-basics

Insert custom annotation in java 'field' using annotate plugin + JAXB (upon xsd -> java)

佐手、 提交于 2019-11-30 18:55:22
Use case: Wanna insert custom annotation to fields in java class generated by JAXB Problem: Using Annotate plugin + JAXB [1], am able to successfully insert custom annotations but they are getting inserted at getter method rather than field. Morphia (mongo DB) annotations (that i actually want to insert) however can annotate only java fields [2]. My test xsd: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1" xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox"> <xsd:element name="hoo" type="External

Insert custom annotation in java 'field' using annotate plugin + JAXB (upon xsd -> java)

荒凉一梦 提交于 2019-11-30 03:49:32
问题 Use case: Wanna insert custom annotation to fields in java class generated by JAXB Problem: Using Annotate plugin + JAXB [1], am able to successfully insert custom annotations but they are getting inserted at getter method rather than field. Morphia (mongo DB) annotations (that i actually want to insert) however can annotate only java fields [2]. My test xsd: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1" xmlns:annox=

JAXB schema to Java Different XmlRootElement name and Class name

限于喜欢 提交于 2019-11-29 15:06:14
I have a xsd schema from which I'm generating some java classes. I'm using jaxb for the generation. I want to be able to generate a class annotated with @XmlRootElement , but I want the @XmlRootElement name property to be different than the name of the generated class. In my xsd I'm defining the following: <xs:element name="customer"> <xs:complexType> <xs:sequence> .... </xs:sequence> </xs:complexType> </xs:element> This piece of code generates the following java class: @XmlRootElement(name = "customer") public class Customer { ... } The name property of the @XmlRootElement is the same as the

Add toString, hashCode, equals while generating JAXB classes in Java

走远了吗. 提交于 2019-11-29 01:48:49
I'm trying to generate JAXB classes from an XSD file programmatically, using Java. I've used the following code snippet to achieve that: .... import java.io.File; import java.io.IOException; import org.xml.sax.InputSource; import com.sun.codemodel.JCodeModel; import com.sun.tools.xjc.api.S2JJAXBModel; import com.sun.tools.xjc.api.SchemaCompiler; import com.sun.tools.xjc.api.XJC; .... .... public static void generateJaxb(String schemaPath, String outputDirectory, String packageName) throws DataLoadingException { try { // Setup schema compiler SchemaCompiler sc = XJC.createSchemaCompiler(); sc

JAXB unmarshalling Custom entities without annotation

隐身守侯 提交于 2019-11-28 08:36:10
问题 We have an xml file which we need to unmarshall(convert into a Java Object). Now the Java object is of third party and I cannot annotate it for unmarshalling. Any idea as to how I can Unmarshal without annotation. Please find my code snippet below JAXBContext context; try { context = JAXBContext.newInstance(Abc.class); Unmarshaller unMarshaller = context.createUnmarshaller(); Abc abc= (Abc) unMarshaller.unmarshal(new FileInputStream("C:\\Documents and Settings\\sandeep.nair\\Desktop\\abc.xml"

Generating hashCode() and equals() when creating Java classes using Mojo Jaxb2 maven plugin

旧城冷巷雨未停 提交于 2019-11-27 14:48:10
The code I'm working on is using jaxb2-maven-plugin from org.codehaus.mojo to generate Java classes from XSD schema. I'm looking for a way to automatically implement equals() and hashCode() methods for those classes, but it seems there is not a way. I know that there are other JAXB2 Maven plugins that do that (http://confluence.highsource.org/display/J2B/Home for example), but I was wondering if anyone of you encountered this issue before and if there's a way for fixing it. I'm generating the classes using the xjc goal. JAXB2 Basics you're mentioning is not a property of maven-jaxb2-plugin ,

JAXB schema to Java Different XmlRootElement name and Class name

喜夏-厌秋 提交于 2019-11-27 07:53:11
问题 I have a xsd schema from which I'm generating some java classes. I'm using jaxb for the generation. I want to be able to generate a class annotated with @XmlRootElement , but I want the @XmlRootElement name property to be different than the name of the generated class. In my xsd I'm defining the following: <xs:element name="customer"> <xs:complexType> <xs:sequence> .... </xs:sequence> </xs:complexType> </xs:element> This piece of code generates the following java class: @XmlRootElement(name =

Generating hashCode() and equals() when creating Java classes using Mojo Jaxb2 maven plugin

折月煮酒 提交于 2019-11-26 18:27:16
问题 The code I'm working on is using jaxb2-maven-plugin from org.codehaus.mojo to generate Java classes from XSD schema. I'm looking for a way to automatically implement equals() and hashCode() methods for those classes, but it seems there is not a way. I know that there are other JAXB2 Maven plugins that do that (http://confluence.highsource.org/display/J2B/Home for example), but I was wondering if anyone of you encountered this issue before and if there's a way for fixing it. I'm generating the

Generating a JAXB class that implements an interface

你说的曾经没有我的故事 提交于 2019-11-26 16:07:49
I'm currently using JAXB to generate java classes in order to unmarshall XML. Now I would like to create a new schema very similar to the first and have the classes that are generated implement the same interface. Say for example, I have two schema files which define XML with similar tags: adult.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:element name="Person"> <xs:complexType> <xs:sequence> <xs:element name="Name" type="xs:string" /> <xs:element name="Age" type="xs:integer" /> <xs:element name="Job" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> kid.xsd <?xml version="1

Generating a JAXB class that implements an interface

不问归期 提交于 2019-11-26 04:44:53
问题 I\'m currently using JAXB to generate java classes in order to unmarshall XML. Now I would like to create a new schema very similar to the first and have the classes that are generated implement the same interface. Say for example, I have two schema files which define XML with similar tags: adult.xsd <?xml version=\"1.0\" encoding=\"UTF-8\"?> <xs:element name=\"Person\"> <xs:complexType> <xs:sequence> <xs:element name=\"Name\" type=\"xs:string\" /> <xs:element name=\"Age\" type=\"xs:integer\"