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

flexjson.factories.EnumObjectFactory Maven / Gradle / Ivy

package flexjson.factories;

import flexjson.ObjectFactory;
import flexjson.JSONException;
import flexjson.ObjectBinder;

import java.lang.reflect.Type;

public class EnumObjectFactory implements ObjectFactory {
    public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) {
        if( value instanceof String ) {
            return Enum.valueOf( (Class)targetType, value.toString() );
        } else {
            throw new JSONException( String.format("%s:  Don't know how to convert %s to enumerated constant of %s", context.getCurrentPath(), value, targetType ) );
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy