public void validate(JSONValue aValue) throws ValidationException { if(!aValue.isInteger()) fail("The value is not a JSONInteger.", aValue); } }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { //lenient to the data to be converted. if(aValue.isDecimal()) return ((JSONDecimal)aValue).getValue().toString(); if(aValue.isInteger()) return ((JSONInteger)aValue).getValue().toString(); if (!aValue.isString()) throw new MapperException("StringMapper cannot map class: " + aValue.getClass().getName()); return ((JSONString) aValue).getValue(); } }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return Long.parseLong(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("LongMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isInteger()) return ((JSONInteger) aValue).getValue().longValue(); else throw new MapperException("LongMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return Byte.parseByte(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("ByteMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isInteger()) return (byte) ((JSONInteger) aValue).getValue().intValue(); else throw new MapperException("ByteMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return Short.parseShort(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("ShortMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isInteger()) return (short) ((JSONInteger) aValue).getValue().intValue(); else throw new MapperException("ShortMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return Integer.parseInt(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("IntegerMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isInteger()) return ((JSONInteger) aValue).getValue().intValue(); else throw new MapperException("IntegerMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return Double.parseDouble(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("DoubleMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isDecimal()) return ((JSONDecimal) aValue).getValue().doubleValue(); else if(aValue.isInteger()) return ((JSONInteger)aValue).getValue().doubleValue(); else throw new MapperException("DoubleMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return new BigInteger(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("BigIntegerMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isInteger()) return ((JSONInteger) aValue).getValue(); else throw new MapperException("BigIntegerMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return new BigDecimal(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("BigDecimalMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isDecimal()) return ((JSONDecimal) aValue).getValue(); else if(aValue.isInteger()) return new BigDecimal(((JSONInteger)aValue).getValue()); else throw new MapperException("BigDecimalMapper cannot map: " + aValue.getClass().getName()); }
public Length(String aName, JSONObject aRule) throws ValidationException { super(aName, aRule); if (aRule.containsKey(ValidatorUtil.PARAM_MIN)) { JSONValue lMin = aRule.get(ValidatorUtil.PARAM_MIN); if (!lMin.isInteger()) { final String lMsg = "Minimum length should be specified using an integer."; throw new ValidationException(lMsg, aRule, "WRONG TYPE"); } else minLength = ((JSONInteger) lMin).getValue().intValue(); } if (aRule.containsKey(ValidatorUtil.PARAM_MAX)) { JSONValue lMax = aRule.get(ValidatorUtil.PARAM_MAX); if (!lMax.isInteger()) { final String lMsg = "Maximum length should be specified using an integer."; throw new ValidationException(lMsg, aRule, "WRONG TYPE"); } else maxLength = ((JSONInteger) lMax).getValue().intValue(); } }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { try { return Float.parseFloat(((JSONString)aValue).getValue()); } catch (NumberFormatException e) { throw new MapperException("FloatMapper cannot map value: " + ((JSONString)aValue).getValue()); } } else if(aValue.isDecimal()) return ((JSONDecimal) aValue).getValue().floatValue(); else if(aValue.isInteger()) return ((JSONInteger)aValue).getValue().floatValue(); else throw new MapperException("FloatMapper cannot map: " + aValue.getClass().getName()); }
/** * 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); }
public Range(String aName, JSONObject aRule) throws ValidationException { super(aName, aRule); if (aRule.containsKey(ValidatorUtil.PARAM_MIN)) { JSONValue lMin = aRule.get(ValidatorUtil.PARAM_MIN); if (!lMin.isNumber()) { final String lMsg = "Minimum length should be specified using a number."; throw new ValidationException(lMsg, aRule, "WRONG TYPE"); } else minValue = cvtNumber((JSONNumber) lMin); } if (aRule.containsKey(ValidatorUtil.PARAM_MAX)) { JSONValue lMax = aRule.get(ValidatorUtil.PARAM_MAX); if (!lMax.isInteger()) { final String lMsg = "Maximum length should be specified using an integer."; throw new ValidationException(lMsg, aRule, "WRONG TYPE"); } else maxValue = cvtNumber((JSONNumber) lMax); } }