public void validate(JSONValue aValue) throws ValidationException { // First we check if we have an array. if(!aValue.isArray()) fail("The value is not a JSONArray.", aValue); } }
public void validate(JSONValue aValue) throws ValidationException { Iterator<JSONValue> lIter = null; if(aValue.isArray()) lIter = ((JSONArray) aValue).getValue().iterator(); else if(aValue.isObject()) lIter = ((JSONObject) aValue).getValue().values().iterator(); else fail("The value is not a JSONComplex, it has no content.", aValue); // Finally we apply the internal rule to all elements. if(lIter != null) { while(lIter.hasNext()) { JSONValue lVal = (JSONValue) lIter.next(); rule.validate(lVal); } } } }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(!aValue.isArray()) throw new MapperException("ArrayMapper cannot map: " + aValue.getClass().getName());
public Object toJava(JSONValue aValue, Class aRawClass, Type[] aTypes) throws MapperException if (!aValue.isArray()) throw new MapperException("CollectionMapper cannot map: " + aValue.getClass().getName()); if (!Collection.class.isAssignableFrom(aRawClass)) throw new MapperException("CollectionMapper cannot map: " + aValue.getClass().getName());
public void validate(JSONValue aValue) throws ValidationException { int lSize = 0; if(aValue.isArray()) lSize = ((JSONArray) aValue).getValue().size(); else if(aValue.isString()) lSize = ((JSONString) aValue).getValue().length(); else if(aValue.isObject()) lSize = ((JSONObject) aValue).getValue().size(); else fail("The value is not a JSONArray, JSONString or JSONObject.", aValue); // If there are lenght specs, we check them. if(minLength != null) { if(lSize < minLength) fail("The size (" + lSize +") is smaller then allowed (" + minLength + ").", aValue); } if(maxLength != null) { if( lSize > maxLength ) fail("The size (" + lSize +") is larger then allowed (" + maxLength + ").", aValue); } } }
/** * Map a JSON representation to a Java object. Since no class nor type hint is passed to the * mapper, this method can only handle the most basic mappings. * @param aValue The JSON value that has to be mapped. * @return he resulting Java POJO. * @throws MapperException When the JSON text cannot be mapped to POJO. */ public static Object toJava(JSONValue aValue) throws MapperException { if(aValue.isArray()) return toJava(aValue, LinkedList.class); else if(aValue.isBoolean()) return toJava(aValue, Boolean.class); else if(aValue.isDecimal()) return toJava(aValue, BigDecimal.class); else if(aValue.isInteger()) return toJava(aValue, BigInteger.class); else if(aValue.isString()) return toJava(aValue, String.class); else return toJava(aValue, Object.class); }