jaxb2

How do you invoke schemagen in Java 11?

蹲街弑〆低调 提交于 2019-11-29 05:08:53
According to Oracle documentation the schemagen tool is removed from the JDK as part of JEP 320 ( http://openjdk.java.net/jeps/320 ). That JEP points to Maven artifacts that now supply the missing tools. The coordinates of the artifacts are wrong in the JEP, updated coordinates are found in an answer to this question: Which artifacts should I use for JAXB RI in my Maven project? What is missing however is how to invoke the tools. There are shell scripts pointed to in the JEP that are in the JAXB-RI Git repository. However those scripts remain undocumented and difficult to invoke. The build

How to execute the JAXB compiler from ANT

心已入冬 提交于 2019-11-29 03:24:57
I am using JAXB on a project. the attraction of JAXB is that it is bundled with the JDK, I have been to use xjc.exe on the command line to generate the .java files from a schema. I can't seem to find the JAXB ant task, sure there is a download at http://jaxb.java.net however i want to use the JAXB that is bundled into the JDK is there some way to call JAXB from ant what class does the xjc.exe call on? <target name="generate-jaxb-code"> <java classname="com.sun.tools.internal.xjc.XJCFacade"> <arg value="-p" /> <arg value="com.example"/> <arg value="xsd/sample.xsd" /> </java> </target> Just went

Using JAXB to support schemas with minor variations

筅森魡賤 提交于 2019-11-28 19:42:23
The Situation I need to support generating XML documents based on schemas that vary only slightly between each other. Specifically, the schemas that I need to support are based on industry standards that change slightly over time and vendors may make their own customized version of them. The Problem I was intending to use JAXB 2 (from Metro) with inheritance as a solution. I expected the package structure to end up something like this: com.company.xml.schema.v1 com.company.xml.schema.v2 com.company.xml.schema.v2.vendorxyz Where the classes in the v2 package would simply extend the classes in

Class Cast Exception when trying to unmarshall xml?

狂风中的少年 提交于 2019-11-28 15:58:11
Trying to get past a class cast exception here: FooClass fooClass = (FooClass ) unmarshaller.unmarshal(inputStream); throws this exception: java.lang.ClassCastException: javax.xml.bind.JAXBElement I don't understand this - as the class was generated by the xjc.bat tool - and the classes it generated I have not altered at all - so there should be no casting problems here - the unmarshaller should really be giving me back a class that CAN be cast to FooClass. Any ideas as to what I am doing wrong? Jon Skeet Does FooClass have the XmlRootElement annotation? If not, try: Source source = new

How to handle forward references of XML IDREF with JAXB XmlAdapter during unmarshal?

淺唱寂寞╮ 提交于 2019-11-28 12:36:44
Is it possible to handle forward references of XML IDREF elements in JAXB XmlAdapter during the unmarshal process? For example, I have the following XML complexType : <xs:complexType name="person"> <xs:complexContent> <xs:sequence> <xs:element name="dateOfBirth" type="xs:dateTime" minOccurs="0"/> <xs:element name="firstName" type="xs:string" minOccurs="0"/> <xs:element name="gender" type="xs:string" minOccurs="0"/> <xs:element name="guardian" type="xs:IDREF" minOccurs="0"/> <xs:element name="homePhone" type="xs:string" minOccurs="0"/> <xs:element name="lastName" type="xs:string" minOccurs="0"/

JaxB marhsalling using interfaces

余生颓废 提交于 2019-11-28 11:28:15
问题 I have the following class, i want to be able to produce xml dynamically based ona an interface, with changing implementations... is that possible... i have tried with little luck... @xmlRootElement public class Vehicles { private String id; private List<VehicleType> types; .... various setters and getters... ... with annotated getters... } public interface VehicleType { public String getName(); } public Car implements VehicleType { private String name; private String wheels; ...various

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"

How to execute the JAXB compiler from ANT

混江龙づ霸主 提交于 2019-11-27 22:07:29
问题 I am using JAXB on a project. the attraction of JAXB is that it is bundled with the JDK, I have been to use xjc.exe on the command line to generate the .java files from a schema. I can't seem to find the JAXB ant task, sure there is a download at http://jaxb.java.net however i want to use the JAXB that is bundled into the JDK is there some way to call JAXB from ant what class does the xjc.exe call on? 回答1: <target name="generate-jaxb-code"> <java classname="com.sun.tools.internal.xjc

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 ,

How do you customize how JAXB generates plural method names?

試著忘記壹切 提交于 2019-11-27 11:54:16
We are using JAXB to generate Java classes and have encountered a few cases where generated plural method names are not correct. For example, where we expect getPhysicians we are getting getPhysicien . How would we customize how JAXB pluralizes specific methods? The schema: <xs:complexType name="physician"> <xs:sequence> ... </xs:sequence> </xs:complexType> <xs:complexType name="physicianList"> <xs:sequence> <xs:element name="Physician" type="physician" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> The generated Java code: ... public class PhysicianList { ...