jaxb2

Class Cast Exception when trying to unmarshall xml?

时光毁灭记忆、已成空白 提交于 2019-11-27 09:40:19
问题 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

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

喜你入骨 提交于 2019-11-27 07:05:30
问题 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=

Is there a need in JAXB implementation for Android?

落花浮王杯 提交于 2019-11-27 06:31:54
问题 As far as I know, there is currently no JAXB implementation which would work on the Android platform. I would like to ask a simple question - Is there a need for JAXB on Android? Being a JAXB enthusiast, I consider writing a JAXB implementation for Android. I probably won't port JAXB RI since it is a bit too fat for the mobile apps, I'd rather write it from scratch. I wrote a JAXB port for JavaScript, so I know this is manageable. But do you guys need it? Or do are you comfortable with other

XSD for having 2 root elements (1 at a time)

蓝咒 提交于 2019-11-27 06:24:19
问题 So here is a complex/retarded situation. I am writing an XSD and there happens to be a requirement where i need 2 root elements (1 at any given time) <xs:element name="booksList"> <xs:complexType> <xs:sequence> <xs:element name="book" type="bookType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> and then <xs:element name="book" type="bookType"></xs:element> at any given time, either of these element will be used as the root element, so an XML would look

Can JAXB marshal by containment at first then marshal by @XmlIDREF for subsequent references?

半城伤御伤魂 提交于 2019-11-27 02:21:37
I'm wondering if it's possible to annotate my classes so that the first time the marshaller encounters an object, it generates an XML element of the appropriate type, but any subsequent reference to this object by anything else will have an XML IDREF entry created? You can leverage the concept of JAXB's XmlAdapter to do something like the following: input.xml The following is the XML document I will use for this example. The 3rd phone-number entry is a reference to the 1st phone-number entry, and the 5th phone-number entry is a reference to the 4th.: <?xml version="1.0" encoding="UTF-8"

Which artifacts should I use for JAXB RI in my Maven project?

…衆ロ難τιáo~ 提交于 2019-11-26 20:05:38
Historically, I always used the following JAXB RI artifacts in my Maven projects: com.sun.xml.bind:jaxb-impl - Runtime com.sun.xml.bind:jaxb-xjc - Schema compiler com.sun.xml.bind:jaxb-jxc - Schema generator Since approximately version 2.2.10* these artifacts are now described as "old" : com.sun.xml.bind:jaxb-impl Old JAXB Runtime module. So it looks like these artifacts are now obsolete. The question is: Which artifacts should be used instead? lexicore After clarification with Oracle, the following artifacts should be used: Runtime If you want to unmarshal XML to Java objects or marshal Java

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

How do you customize how JAXB generates plural method names?

与世无争的帅哥 提交于 2019-11-26 15:45:25
问题 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"/> <

JAXB: how to marshall map into <key>value</key>

痴心易碎 提交于 2019-11-26 11:40:35
The question is about JAXB Map marshalling - there is plenty of examples on how to marhsall a Map into a structure like follows: <map> <entry> <key> KEY </key> <value> VALUE </value> </entry> <entry> <key> KEY2 </key> <value> VALUE2 </value> </entry> <entry> ... </map> In fact, this is natively supported by JAXB. What I need, however, is the XML where key is the element name, and value is its content: <map> <key> VALUE </key> <key2> VALUE2 </key2> ... </map> I didn't succeed implementing my Map adapter the way it is recommended by JAXB developers ( https://jaxb.dev.java.net/guide/Mapping_your

Can JAXB marshal by containment at first then marshal by @XmlIDREF for subsequent references?

筅森魡賤 提交于 2019-11-26 10:02:13
问题 I\'m wondering if it\'s possible to annotate my classes so that the first time the marshaller encounters an object, it generates an XML element of the appropriate type, but any subsequent reference to this object by anything else will have an XML IDREF entry created? 回答1: You can leverage the concept of JAXB's XmlAdapter to do something like the following: input.xml The following is the XML document I will use for this example. The 3rd phone-number entry is a reference to the 1st phone-number