cancel
Showing results for 
Search instead for 
Did you mean: 

Returning a complex HashMap via web service does not work

patrik_spiess
Participant
0 Kudos

Hi,

I try to return

public class HardwareQueryResponse {

	HashMap<Feature, ArrayList<String>> featureToDeviceMap;
	// ... some more fields

	public HashMap<Feature, ArrayList<String>> getFeatureToDeviceMap() {
		return featureToDeviceMap;
	}

	public void setFeatureToDeviceMap(
			HashMap<Feature, ArrayList<String>> featureToDeviceMap) {
		this.featureToDeviceMap = featureToDeviceMap;
	}
	// ... some more getters and setters
}

via a web service. I add a correct entry (a feature object as key and a string array with one entry as value) to the object and return it. However, the result seen in WSNavigator only contains the key and an empty value tag.


    <ns2:queryAllHardwareInformationResponse xmlns:ns2="http://sap.com/sii/deviceRepository/">
      <return>
        <featureToDeviceMap>
          <entry>
            <key>
              <description>electronically operated</description>
              <name>panoramic window</name>
            </key>
            <value/>
          </entry>
        </featureToDeviceMap>
        // ... some more stuff
      </return>
    </ns2:queryAllHardwareInformationResponse>

I would expect the reply to contain the array in the "value" tag. Any clue?

Accepted Solutions (1)

Accepted Solutions (1)

Vlado
Advisor
Advisor
0 Kudos

Hi,

There is a limitation that a HashMap cannot be used as a top-level parameter in a WS operation. However, it is possible to be used in another structure (wrapper type) which is passed as the parameter for the WS method.

For instance:


public class Wrapper {

	HashMap<Feature, ArrayList<String>> featureToDeviceMap;
 
	public HashMap<Feature, ArrayList<String>> getFeatureToDeviceMap() {
		return featureToDeviceMap;
	}
 
	public void setFeatureToDeviceMap(
			HashMap<Feature, ArrayList<String>> featureToDeviceMap) {
		this.featureToDeviceMap = featureToDeviceMap;
	}

}

public class HardwareQueryResponse {

	Wrapper wrapper;
	// ... some more fields

	public Wrapper getWrapper() {
		return wrapper;
	}

	public void setWrapper(Wrapper wrapper) {
		this.wrapper = wrapper;
	}
	// ... some more getters and setters
}

HTH!

\-- Vladimir

patrik_spiess
Participant
0 Kudos

Hi Vladimir,

thanks for this valuable tip (as always from you). I will try it out as soon as I have time to.

Best regards,

Patrik

Answers (1)

Answers (1)

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

The clue I have is to ask you to read through the docs, as I remember especially hash types where not available two years ago. I'm not sure if this has changed until today.

So better check if those data types are supported at all.

Regards,

Benny