Open Source Repository

Home /json/flexjson-2.1 | Repository Home



flexjson/factories/MapObjectFactory.java
package flexjson.factories;

import flexjson.ObjectFactory;
import flexjson.ObjectBinder;

import java.lang.reflect.Type;
import java.lang.reflect.ParameterizedType;
import java.util.Map;
import java.util.HashMap;

public class MapObjectFactory implements ObjectFactory {
    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        iftargetType != null ) {
            iftargetType instanceof ParameterizedType ) {
                ParameterizedType ptype = (ParameterizedTypetargetType;
                return context.bindIntoMap( (Map)value, new HashMap<Object,Object>(), ptype.getActualTypeArguments()[0], ptype.getActualTypeArguments()[1] );
            }
        }
        return context.bindIntoMap( (Map)value, new HashMap<Object,Object>(), null, null );
    }
}