Sunday, September 13, 2009

Reading values from Java HashMap in Flex Actionscript

Its very common situation when java application return key-value pair values in a hashmap to web-component. As flex is little different in terms of java structure mapping and doesn't have implicit mapping object for java hashmap. Although it converts it to untype array of object and contains Dictionary which somehow similair to HashMap to hold key-value pair values.


function to read values from java hashmap, you can store it in Flex Dictionary

public function readHashMap(javaServiceResult:Object):void
{
var classInfo:Object = ObjectUtil.getClassInfo(javaServiceResult);
for each (var properties:QName in classInfo.properties)
{
var key:String = properties.localName;
var value:String = javaServiceResult[key];
trace('Key: '+key+' Value: '+value);
}
}