發表文章

目前顯示的是有「JAXB」標籤的文章

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser

When you encounter the following error that related to web service. java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser Solution 1: Ensure no xercesImpl.jar in your classpath since the implementation of xerce is built-in wiht JAVA SE 1.6. Solution 2: Use XmlJavaTypeAdapter [ @XmlJavaTypeAdapter(JaxbDateAdapter.class)] to convert XMLGregorianCalendar type to Date type. XMLGregorianCalendar is the built-in Java data type for JAXB mapping with datetime. Example: Binding.xjb <?xml version="1.0" encoding="UTF-8"?> <bindings xmlns="http://java.sun.com/xml/ns/jaxb"                 xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"                 xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"               ...

java.lang.ClassCastException: javax.xml.bind.JAXBElement

When your XSD have no XMLRootElement that contains all types in one element, the code below is not applicable: FooClass foo = (FooClass)unMarshaller.unmarshal(reader); You should use the code below: JAXBElement < FooClass > root = unmarshaller . unmarshal ( inputStream , FooClass . class ); FooClass foo = root . getValue (); XSD Comparison: <xsd:element name="brs-reprint-param" type="brsReprintParam"> <xsd:key name="reportId"> <xsd:selector xpath="./report"/> <xsd:field xpath="@id"/> </xsd:key> </xsd:element> <xsd:complexType name="brsReprintParam"> <xsd:sequence> <xsd:element name="report" type="reprintReport.CT" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:element name="brs-reprint-param" > <xsd:complexType> ...