Actually, the problem is NOT how to do it, but if it's a design mistake. I'm worried because I've read a lot about using only standard data types in WS. However, I had no problem implementing one that receives a HashMap, and filling that parameter from PHP with nuSoap.
I have a ParameterBean class with this members (plus getters and setters of course), which includes a HashMap.
private int ID;
private String value;
private String name;
private HashMap<Integer, String> map = new HashMap<Integer, String>();
And a service that receives an instance from this class. Then from the PHP client I invoke:
$map = array(1 => 'Foo', 2 => 'Bar');
$paramsp = array(
'ID' => '1',
'value' => 'Some Value',
'name' => 'A Name',
'map' => $map
);
$params = array($paramsp);
$resp = $client->call('test',$params);
print_r($client->response);
It works like a charm! Question is: Is this frowned upon? Will this result in a headache in the future in some way?
A HashMap is a pretty dang standard data type and should present no problems when used in a web service.
As you've seen, both PHP and Java have no problem dealing with hash maps. JSON supports them (though they're called "objects", and don't have the explicit typing of Java).
While truly esoteric datatypes might cause problems for web services that are expected to be widely interoperable, hash maps are not in that category and should be used without worry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With