/** * Back up one character. This provides a sort of lookahead capability, * so that you can test for a digit or letter before attempting to parse * the next number or identifier. * * @throws JSONException if you try and step back twice it will throw this exception */ public void back() throws JSONException { if (useLastChar || index <= 0) { throw new JSONException("Stepping back two steps is not supported"); } index-= 1; useLastChar= true; }
public OutputHandler write(String value) { try { out.write(value); } catch (IOException e) { throw new JSONException("There was a problem writing output to the Writer.", e); } return this; }
public int write(String value, int start, int end) { try { out.write(value, start, end - start); return end; } catch (IOException e) { throw new JSONException("There was a problem writing output to the Writer.", e); } }
public int write(String value, int start, int end, String append) { try { out.write(value, start, end - start); out.write(append); return end + 1; } catch (IOException e) { throw new JSONException("There was a problem writing output to the Writer.", e); } }
private void putOnce(Map<String, Object> jsonObject, String key, Object value) { if (key != null) { if (!jsonObject.containsKey(key)) { jsonObject.put(key, value); } else { throw new JSONException("Duplicate key \"" + key + "\""); } } }
public Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass) { try { return simpleDateFormatter.parse(value.toString()); } catch (ParseException e) { throw new JSONException(String.format("Failed to parse %s with %s pattern.", value, simpleDateFormatter.toPattern()), e); } } }
public JSONException cannotConvertValueToTargetType(Object value, Class targetType) { return new JSONException(String.format("%s: Can not convert %s into %s", currentPath, value.getClass().getName(), targetType.getName())); }
private Type resolveParameterizedTypes(Type genericType, Type targetType) { if (genericType instanceof Class) { return genericType; } else if (genericType instanceof ParameterizedType) { return genericType; } else if (genericType instanceof TypeVariable) { return targetType; } else if (genericType instanceof WildcardType) { return targetType; } else if (genericType instanceof GenericArrayType) { return ((GenericArrayType) genericType).getGenericComponentType(); } else { throw new JSONException(currentPath + ": Unknown generic type " + genericType + "."); } }
throw new JSONException(currentPath + ": Unknown type " + targetType);
protected Object instantiate(Class clazz) { try { Constructor constructor= clazz.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (InstantiationException e) { throw new JSONException(currentPath + ":There was an exception trying to instantiate an instance of " + clazz.getName(), e); } catch (IllegalAccessException e) { throw new JSONException(currentPath + ":There was an exception trying to instantiate an instance of " + clazz.getName(), e); } catch (InvocationTargetException e) { throw new JSONException(currentPath + ":There was an exception trying to instantiate an instance of " + clazz.getName(), e); } catch (NoSuchMethodException e) { throw new JSONException(currentPath + ": " + clazz.getName() + " lacks a no argument constructor. Flexjson will instantiate any protected, private, or public no-arg constructor.", e); } }
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)); } } }
/** * Make a JSONException to signal a syntax error. * * @param message The error message. * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
throw new JSONException(exc);
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)); } } }
protected Class findClassInMap(Map map, Class override) { if (override == null) { Integer reference= (Integer) map.get("@ref"); if (reference != null) return getReferences().get(reference).getClass(); String classname= (String) map.remove("class"); try { if (classname != null) { return Class.forName(classname); } else { return null; } } catch (ClassNotFoundException e) { throw new JSONException( /*String.format( "%s: Could not load %s", currentPath, classname ), */e); } } else { return override; } }
throw new JSONException(exc);
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);
throw new JSONException(exc);