private BigDecimal cvtNumber(JSONNumber aNum) { if (aNum.isInteger()) return new BigDecimal(((JSONInteger) aNum).getValue()); else return ((JSONDecimal) aNum).getValue(); } }
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()); }