jaxb

JAXB - generating classes from XSD - converting enums to strings

Using JAXB, we generate our Java beans directly. In the XSD, we have an enumerated type: <xs:simpleType name="promptBeforeCloseType"> <xs:restriction base="xs:string"> <xs:enumeration value="default"/> <xs:enumeration value="always"/> <xs:enumeration value="never"/> </xs:restriction> </xs:simpleType> JAXB ge...

xjc binding file for <extension base = "anyType"/> throws error

I have xsd defination <element name="primaryKey" nillable="false"> <complexType mixed="false"> <complexContent mixed="false"> <extension base="anyType"/> </complexContent> </complexType> </element> and i using binding file to <jxb:bindings node="//xs:extension[@base=...

Mapping Java with JAXB annotations to XSD keys/keyrefs

We are using JAXB to map Java classes into XML files. Currently we use the Java-to-XSD approach by annotating the Java classes. This works fine in general but we've hit the following problem now: we want an attribute of one XML element to refer to another XML element by it's name/ID. Imagine some XML describing a conceptual schema, with...

How to handle different versions of xsd files in one java application?

The Facts In my java application I have to handle XML files with different schema versions (xsd files) simultaneously. The content of the XML files changed only a little between the different versions, so I'd like to use mainly the same code to handle it and just do some case distictions dependent on the version of the used schema. Cur...

Is there any way to restict the marshalling depth for object graphs in JAXB?

I'm using JAXB for quick-and-dirty XML generation. I have a class that represents a tree structure: @XmlRootElement(name = "element") public class Element { // [...] @XmlElementWrapper(name="childs") @XmlElementRef public List<Element> getChilds() { /*...*/ } } I want to restrict the depth up to which the child collection is...

How to write an external binding file for xjc?

The documentation of JAXB xjc says: -b Specify one or more external binding files to process. (Each binding file must have it's own "-b" switch.) The syntax of the external binding files is extremely flexible. You may have a single binding file that contains customizations for multiple schemas or you can break the customizatio...

How do I annotate a JAXB property to use xsd:time rather than xsd:datetime?

I have a JAXB class like this: public class Game { private Date startTime; @XmlElement public Date getStartTime() { return startTime; } public void setStartTime(Date startTime) { this.startTime = startTime; } } which results in an .xsd where startTime has type xsd:datetime. I want it to be xsd...

Is there a problem initializing a JAXBContext with a package in a library?

I'm trying to initialize a JAXBContext like so: JAXBContext jaxbContext = JAXBContext.newInstance("ebay.apis.eblbasecomponents"); When the code is run, however, I get the following run time error: Exception in thread "main" java.lang.NoClassDefFoundError: ebay/apis/eblbasecomponents/ObjectFactory Caused by: java.lang.ClassNotFoundExc...

Jaxb2Marshaller and primitive types

Is it possible to create a web service operation using primitive or basic Java types when using the Jaxb2Marschaller in spring-ws? For example a method looking like this: @Override @PayloadRoot(localPart = "AddTaskRequest", namespace = "http://example.com/examplews/") public long addTask(final Task task) throws AddTaskFault { // do som...

Need help in finding exception "javax.xml.bind.UnmarshalException - with linked exception:"

I tried to store a resume in an online CRM on trying to save that i got the following exception javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.stream.XMLStreamException: ParseError at [row,col]:[73,12] Message: Character reference "&#x18" is an invalid XML character.] i can store the resumes using th...

How do I add a namespace attribute to an element in JAXB when marshalling?

I'm working with eBay's LMS (Large Merchant Services) and kept running into the error: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize. After alot of trial and error I traced the problem down. It turns out this works: <?xml version="...

STaX code is not working with JAXB

Found a sample STaX code in below link: http://www.javarants.com/2006/04/30/simple-and-efficient-xml-parsing-using-jaxb-2-0/comment-page-1/ The below code doesn't work. I am not what is missing. JAXBContext ctx = JAXBContext.newInstance("com.sampullara.findbugs.om"); Unmarshaller um = ctx.createUnmarshaller(); int bugs ...

grails webservices returning an object List

I'm trying to expose a webservice via grails & cxf grails plugin. this is the skeleton of the webservice: class IssueService { static expose=['cxf'] def List issueList(){ def list = Issue.list() return list } def Issue singleIssue(id){ def currentIssue = Issue.findById(id) return currentIssue ...

How to stream large Files using JAXB Marshaller?

Hi. The Problem I'm facing is how to marshall a large list of objects into a single XML File, so large I can not marshall the complete list in one step. I have a method that returns these objects in chunks, but then I marshall these using JAXB, the marshaller returns with an exception that these objects are no root elements. This is ok ...

In Java for XML marshalling/unmarshalling which utility should we use from JAXB, JIBX, CASTOR, ADB etx?

In Java for XML marshalling/unmarshalling one can use JAXB, JIBX, CASTOR, ADB etc. But out of these which is most generic & commonly used? Or is there any other utility available? ...

JAXB minOccurs=0. Element exists or not?

I have an XML schema: <xsd:element name="Person"> <xsd:complexType> <xsd:sequence> <xsd:element name="name" type="xsd:string" /> <xsd:element name="lat" type="xsd:double" minOccurs="0"/> <xsd:element name="lon" type="xsd:double" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> And I have an XML message:...

jax-ws: how to get a handle to start/end of processing incoming soap message

Situation: jax-ws web service on Weblogic appserver; wsdl first development, jaxb customizations in external binding file. I would like to get a handle to the actual jaxb context that will process the incoming soap xml message, before it has been unmarshalled into java objects. Then I would like to get the unmarshaller of this jaxb con...

Find if InputStream of DataHandler is empty

In my application I develop web service that get attached file. The file is mapped to DataHandler object via JaxB, and I have access to the file via DataHandler.getInputStream() My problem is this: When the file attribute exist in the web service request, but no file is attached, I still get the DataHandler object, and its getInputStrea...

jaxb, get the original xml after unmarshalling

I've a simple little servlet, basically: void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JAXBContext jaxb = myContext.getXMLContext().getSearchparamContext(); SearchParams params = null; try { Unmarshaller um = jaxb.createUnmarshaller(); um.setSch...

Do Domain Classes usually get JPA or JAXB Annotations or both?

I have a Java enterprise application that provides a web service, has a domain layer, and a hibernate persistence layer. In this particular case, there is not a huge difference (at the moment) between the objects I send over the wire, the domain objects, and the persistence objects. Currently the application uses DTO's on the persis...