Package flexjson.factories

Source Code of flexjson.factories.EnumObjectFactory

package flexjson.factories;

import java.lang.reflect.Type;

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

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));
    }
  }
}
TOP

Related Classes of flexjson.factories.EnumObjectFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.