public void validate(JSONValue aValue) throws ValidationException { if(!aValue.isDecimal()) fail("The value is not a JSONDecimal.", 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 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 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 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); }