1

My question is: how does jax-ws generate the unmarshal code associated with the @XmlJavaTypeAdapter? I don't see the adapter class(es) in the client code (instead they are broken out into their adapted objects). Thus, how does the client know how to unmarshal the returned marshaled response when the web service method is invoked?


Details:

I am using the @XmlJavaTypeAdapter annotation inside of another @XmlJavaTypeAdapter annotation in order to turn a Map<> into an ArrayList. The marshaled result is coming out fine. My jax-ws generated client doesn't seem to be able to unmarshal the result though. Instead, I just get a null Object.

Here is the XML that gets sent to the client:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <dlwmin:getRefTableResponse xmlns:dlwmin="http://service.web.test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <wsRefDataObject>
        <map>
           <entry>
              <key>05</key>
              <value>
                 <columns>
                    <entry>
                       <key>state</key>
                       <value>CA</value>
                    </entry>
                    <entry>
                       <key>code</key>
                       <value>05</value>
                    </entry>
                 </columns>
              </value>
           </entry>
        </map>
     </wsRefDataObject>
  </dlwmin:getRefTableResponse>

Here is my Adapter Class for the WsRefDataOject:

I use the same logic for the ReferenceDataEntry unmarshal code (Object of Map).

public class MyMapAdapter extends XmlAdapter<MyMapType, Map<String,ReferenceDataEntry>> {      

public MyMapType marshal(Map<String,ReferenceDataEntry> bt) throws Exception {
    MyMapType myMapType =  new MyMapType();
    for(Map.Entry<String,ReferenceDataEntry> entry : bt.entrySet()) {   
        MyMapEntryType myMapEntryType = new MyMapEntryType();
        myMapEntryType.key = entry.getKey();
        myMapEntryType.value = entry.getValue();
        myMapType.entry.add(myMapEntryType);
    }
    return myMapType;
    }

public Map<String, ReferenceDataEntry> unmarshal(MyMapType v) throws Exception {
    Map<String, ReferenceDataEntry> map = new HashMap<String, ReferenceDataEntry>();
    for(MyMapEntryType myEntryType : v.entry){
        map.put(myEntryType.key, myEntryType.value);
    }
    return map;
}

}

I am able to set a breakpoint in the marshal code and step through it in the service; however, I'm not sure when/where the unmarshal code is stored/called. The adapter classes are not generated in the client and so I'm not sure how the client is supposed to know how to unmarshal the returned xml.

Here is the generated WsRefDataObject class and the generated ReferenceDataEntry class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "wsRefDataObject", namespace = "http://service.web.test/", propOrder = {
"map"})
public class WsRefDataObject {

protected MyMapType map;

/**
 * Gets the value of the map property.
 * 
 * @return
 *     possible object is
 *     {@link MyMapType }
 *     
 */
public MyMapType getMap() {
    return map;
}

/**
 * Sets the value of the map property.
 * 
 * @param value
 *     allowed object is
 *     {@link MyMapType }
 *     
 */
public void setMap(MyMapType value) {
    this.map = value;
}}


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "referenceDataEntry", namespace = "http://service.web.test/", propOrder = {
"columns"})
public class ReferenceDataEntry {

protected RefMapType columns;

/**
 * Gets the value of the columns property.
 * 
 * @return
 *     possible object is
 *     {@link RefMapType }
 *     
 */
public RefMapType getColumns() {
    return columns;
}

/**
 * Sets the value of the columns property.
 * 
 * @param value
 *     allowed object is
 *     {@link RefMapType }
 *     
 */
public void setColumns(RefMapType value) {
    this.columns = value;
}} 


Any ideas on what's causing the null object in the client?

Bryan
  • 11
  • 1
  • Hi, I am also getting the same issue. My `Unmarshal` method provides `NULL` value even though it has value in `XML`. If you remember can you please let me know what you did to fix this issue? – BATMAN_2008 May 20 '21 at 12:08

0 Answers0