All Downloads are FREE. Search and download functionalities are using the official Maven repository.

flexjson.factories.IntegerObjectFactory Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
package flexjson.factories;

import flexjson.ObjectFactory;
import flexjson.ObjectBinder;

import java.lang.reflect.Type;

public class IntegerObjectFactory implements ObjectFactory {
    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        if (value instanceof Number) {
            return ((Number) value).intValue();
        } else {
            try {
                return Integer.parseInt(value.toString());
            } catch (Exception e) {
                throw context.cannotConvertValueToTargetType(value, Integer.class);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy