Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>1.Does eclipse link Dynamic JAXB officially support XML to JSON and viceversa conversions as I have tried above, as I could not see any such examples?</p> </blockquote> <p><a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow"><strong>EclipseLink JAXB (MOXy)</strong></a>'s Dynamic JAXB supports all of the same features as its regular JAXB including JSON-binding.</p> <blockquote> <p>2.How to avoid the above nullpointer exception and still have an element named "type" defined as part of the schema? Is this a bug? Are there any workarounds? I have written the demo code only to highlight the same problem I face elsewhere where I use multiple XML schemas and require a namespace aware handling for JSON conversion.</p> </blockquote> <p>You could change your code to the following:</p> <pre class="lang-java prettyprint-override"><code> // JSON-&gt;JAVA-&gt;XML JAXBUnmarshaller jsonUnmarshaller = jaxbContext.createUnmarshaller(); jsonUnmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json"); // Since there is no root node in your JSON document you should set this flag jsonUnmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); // Since there is no root node to uniquely identify the class you need // to supply one in the unmarshal method. To get the "class" for a // DynamicEntity you can do the following: Class customerType = jaxbContext.getDynamicType("generated.Customer").getJavaClass(); StreamSource json = new StreamSource("src/forum17446153/customer.json"); JAXBElement&lt;DynamicEntity&gt; myroot = (JAXBElement)jsonUnmarshaller.unmarshal(json, customerType); DynamicEntity myResponse = myroot.getValue(); // Since the customer type is named in the XML schema there isn't // a root element associated with the type. This means you will need // to wrap in in an instance of JAXBElement to marshal it., JAXBElement jaxbElementResponse = new JAXBElement(new QName("customer"), customerType, myResponse); marshaller.marshal(jaxbElementResponse, System.out); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload