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 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()); }