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)); } } }
public Class locate(ObjectBinder context, Path currentPath) throws ClassNotFoundException { Object source= context.getSource(); if (source instanceof Map) { Map map= (Map) source; return types.get(map.get(fieldname)); } else { throw new JSONException(String.format("%s: Don't know how to locate types for source %s using fieldname %s. TypeLocator requires the source object be a java.util.Map in order to work.", context.getCurrentPath(), source.getClass(), fieldname)); } } }
public <T extends Collection<Object>> T bindIntoCollection(Collection value, T target, Type targetType) { Type valueType= null; if (targetType instanceof ParameterizedType) { valueType= ((ParameterizedType) targetType).getActualTypeArguments()[0]; } jsonStack.add(value); objectStack.add(target); getCurrentPath().enqueue("values"); for (Object obj : value) { target.add(bind(obj, valueType)); } getCurrentPath().pop(); objectStack.pop(); jsonStack.pop(); return target; }
public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) { List list= (List) value; context.getCurrentPath().enqueue("values"); try { Class memberClass= targetClass.getComponentType() != null ? targetClass.getComponentType() : context.findClassAtPath(context.getCurrentPath()); if (memberClass == null) throw new JSONException("Missing concrete class for array. You might require a use() method."); Object array= Array.newInstance(memberClass, list.size()); for (int i= 0; i < list.size(); i++) { Object v= context.bind(list.get(i), memberClass); Array.set(array, i, v); } return array; } catch (ClassNotFoundException ex) { throw new JSONException(String.format("%s: Could not find class %s", context.getCurrentPath(), ex.getMessage()), ex); } finally { context.getCurrentPath().pop(); } } }
throw new JSONException(String.format("%s: Don't know how to bind %s into class %s. You might need to use an ObjectFactory instead of a plain class.", getCurrentPath().toString(), value, clazz.getName()));
throw new JSONException(String.format("%s: Parsing date %s was not recognized as a date format", context.getCurrentPath(), value)); throw new JSONException(String.format("%s: Error encountered trying to instantiate %s", context.getCurrentPath(), ((Class) targetType).getName()), e); throw new JSONException(String.format("%s: Error encountered trying to instantiate %s. Make sure there is a public constructor that accepts a single Long.", context.getCurrentPath(), ((Class) targetType).getName()), e); throw new JSONException(String.format("%s: Error encountered trying to instantiate %s. Make sure there is a public constructor that accepts a single Long.", context.getCurrentPath(), ((Class) targetType).getName()), e);
throw new JSONException(context.getCurrentPath() + ":There was an exception trying to instantiate an instance of " + targetClass.getName(), e); throw new JSONException(context.getCurrentPath() + ":There was an exception trying to instantiate an instance of " + targetClass.getName(), e); throw new JSONException(context.getCurrentPath() + ":There was an exception trying to instantiate an instance of " + targetClass.getName(), e); throw new JSONException(context.getCurrentPath() + ": " + targetClass.getName() + " lacks a no argument constructor. Flexjson will instantiate any protected, private, or public no-arg constructor.", e);
try clazz= locator.locate(context, context.getCurrentPath()); if (clazz != null) throw new JSONException(String.format("%s: Could not find class %s", context.getCurrentPath(), ex.getMessage()), ex); throw new JSONException(String.format("%s: Could not instantiate class %s", context.getCurrentPath(), clazz.getName()), e); throw new JSONException(String.format("%s: Problem while instantiating class %s", context.getCurrentPath(), clazz.getName()), e); throw new JSONException(String.format("%s: Could not find a no-arg constructor for %s", context.getCurrentPath(), clazz.getName()), e); throw new JSONException(String.format("%s: Problem while invoking the no-arg constructor for %s", context.getCurrentPath(), clazz.getName()), e);