Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending HashMap parameter to Web Service from PHP

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?

like image 332
Federico Cristina Avatar asked Nov 14 '22 01:11

Federico Cristina


1 Answers

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.

like image 111
blahdiblah Avatar answered Dec 23 '22 13:12

blahdiblah