I'm stuck and looking for anybody with ideas. I have a multi-dimensional
PHP array that I want to pass into a Java method that expects a HashMap. So
far, so good. I found that I could not pass the array in directly, but I
could pass the php array into a HashMap constructor and then pass that:
// simplified php code to illustrate the problem
$phpArray = array(
"foo" => "bar",
"baz" => array("x", "y", "z")
);
$hm = new Java("java.util.HashMap", $phpArray);
$myObj->myMethod($hm);
So far, so good. The problem is that the Java code expects one of the
members of the HashMap to be of type String[]:
// simplified java code to illustrate the problem
// hash is the passed-in HashMap<String, Object>
String[] stringArray;
stringArray = (String[])hash.get("baz");
This fails with a ClassCastException because when the HashMap was created,
the inner array became a HashMap, not an array, and the HashMap cannot be
cast to a String[]. I know if you pass an indexed php array as an argument
to a Java method that expects an array, it will be cast appropriately, but
in this case, the bridge does not have that information available to it, and
apparently defaults to a HashMap for the inner array.
Is there any way that I can make this work without digging into the Java
source? I've tried multiple methods of "tricking" the bridge into giving me
a Java String[], but it always outsmarts me and makes it a php array().
Michael.
|