Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB unmarshal has always null value for nested object
    primarykey
    data
    text
    <p>I have a web-service, defined by writing its WSDL and underlaying XSD, and the java server code classes / java bindings were generated using JAXB/xjc.</p> <p>Everything looks fine service is running properly... but for every request (looking well-formed after receiving when looking on log-output) the nested elements seem to be always null when accessing through my java code.</p> <p>Can someone figure out why customerId.getCustomer() always returns null?</p> <h2>My XSD (partly):</h2> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;schema xmlns:tip="http://example.org/tip" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.org/tip/pro"&gt; &lt;complexType name="id"&gt; &lt;attribute name="id" type="int" use="required"/&gt; &lt;attribute name="name" type="string" use="optional"/&gt; &lt;/complexType&gt; &lt;complexType name="customer_id"&gt; &lt;sequence&gt; &lt;element name="customer" type="tip:id" minOccurs="0"/&gt; &lt;/sequence&gt; &lt;/complexType&gt; &lt;element name="get_customer_request" type="tip:customer_id"/&gt; &lt;/schema&gt; </code></pre> <h2>The generated class CustomerId:</h2> <pre class="lang-java prettyprint-override"><code>@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "customer_id", propOrder = {"customer"}) public class CustomerId { protected Id customer; public Id getCustomer() { return customer; } public void setCustomer(Id value) { this.customer = value; } } </code></pre> <p>The generated class for Id look similar, I don't think there is something special. In my request handler I got the following extract:</p> <h2>Handler:</h2> <pre class="lang-java prettyprint-override"><code>JAXBElement&lt;?&gt; request = requestHandler.unmarshallRequest(inputStream); Object jaxbClass = request.getDeclaredType(); expectedClass = CustomerId.class; // next line does not throw exception with given XML if (jaxbClass != expectedClass) throw new IllegalArgumentException(); CustomerId customerId = (CustomerId)request.getValue(); if (customerId == null) { logInfo("customerId: null"); } else if (customerId.getCustomer() == null) { // this is the part that always will be executed... why? logInfo("customerId.customer: null"); } else { logInfo("customer id: " + customerId.getCustomer().getId()); // return mbean.getCustomer(customerId); } </code></pre> <h2>And finally an example request XML:</h2> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;m:get_customer_request xmlns:m="http://example.org/tip/pro"&gt; &lt;customer id="0" name="help"/&gt; &lt;/m:get_customer_request&gt; </code></pre> <p>I stripped out SOAP envelope and body tags, since this is not causing any trouble. Can anyone see, what I am doing wrong? (I am pretty sure, I do...) Thanks for your effords!</p>
    singulars
    1. This table or related slice is empty.
    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