Skip to main content

Posts

Showing posts with the label jaxb

How do i write objects that i have no control over in jaxb?

I am trying to find a way to marshall classes that i have no access to. I am trying to achieve something like this: @XmlRootElement(name="bar") class Bar { @XmlAttribute private Foo foo; @XmlAttribute private String baz; } which should result in a xml file like this: <bar baz="stuff" foo="otherstuff"/> Is this possible? I tried to fiddle with @XmlJavaTypeAdapter with no sucess.

Why do JAXB generated classes have protected members and how can I change this?

I have been searching the internet for a reason why JAXB generated classes have protected members (all of them, regardless of inheritance). I would like the members to be private instead. My search has come up empty. I have normal xsd files which are converted into java classes using maven and jaxb. Ideally the generated members should be private but I cannot find a way to achieve this. Is there a way to modify this default behaviour? Thanks. [edited first sentence]

Unmarshalling returned null object from a successfully marshalled XML

i have the following classes which is marshalled as an XML <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <customer id="100"> <age>21</age> <hobbies> <hobby> <cost>sd</cost> <name>na</name> </hobby> <hobby> <cost>sd</cost> <name>nb</name> </hobby> </hobbies> <name>test</name> </customer> However, when i tried to unmarshall, I can only create the customer object but not hobby, which returns null Am i doing something wrong here? The problem seems to be with the XML hierarchy? package com.mytest.jxb; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlEle

Exception while trying to use jersey and jaxb

The following code: @POST @Path("/previous-status/{current}") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.TEXT_PLAIN) public String getPreviousStepStatus(@PathParam("current") JAXBElement<WorkflowStep> step) { WorkflowStep wfStep = step.getValue(); return DBAccessor.getPrevStepStatus(wfStep); } Produces the following exception: javax.servlet.ServletException: Servlet.init() for servlet Jersey Rest Service threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) org.apach