public void validate(JSONValue aValue) throws ValidationException { if(!aValue.isString()) fail("The value is not a JSONString." ,aValue); } }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if (!aValue.isString()) throw new MapperException("CharacterMapper cannot map class: " + aValue.getClass().getName()); final String lRepr = ((JSONString) aValue).getValue(); if(lRepr.length() != 1) throw new MapperException("CharacterMapper cannot map value: " + lRepr); return lRepr.charAt(0); } }
public void validate(JSONValue aValue) throws ValidationException { if(!aValue.isString()) fail("The value is not a JSONString." ,aValue); final String lString = ((JSONString) aValue).getValue(); Matcher lMatcher = pattern.matcher(lString); if(!lMatcher.matches()) { fail("The string: \"" + lString + "\" does not match the pattern: \"" + representation + "\".", aValue); } } }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if(aValue.isString()) { return Boolean.parseBoolean(((JSONString)aValue).getValue()); } else if(aValue.isBoolean()) { return ((JSONBoolean) aValue).getValue(); } else throw new MapperException("BooleanMapper cannot map: " + aValue.getClass().getName()); }
public Object toJava(JSONValue aValue, Class aRequestedClass) throws MapperException { if (!aValue.isString()) throw new MapperException("DateMapper cannot map class: " + aValue.getClass().getName()); if(DateMapper.isTimeZoneIgnored()) return fromISO8601(((JSONString) aValue).getValue().trim()); else return fromISO8601(((JSONString) aValue).getValue().trim(),false); } //Created on 5/12/2006 by Changdong Li
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()) throw new MapperException("EnumMapper cannot map class: " + aValue.getClass().getName()); if(aRequestedClass.isEnum()) { Object[] lEnumVals = aRequestedClass.getEnumConstants(); for(Object lEnumVal: lEnumVals) { if(lEnumVal.toString().equals(((JSONString)aValue).getValue())) return lEnumVal; } } else { final String lMsg = "Enum mapper tried to handle a non-enum class: " + aRequestedClass; throw new MapperException(lMsg); } final String lMsg = "The enum class *is found* but no matching value could be found. Enum Class: " + aRequestedClass + ", unknown value: " + ((JSONString)aValue).getValue(); throw new MapperException(lMsg); } }
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 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()); }
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); } } }
if(lRule.containsKey(PARAM_NAME) && lRule.get(PARAM_NAME).isString()) lRuleName = ((JSONString) lRule.get(PARAM_NAME)).getValue();
/** * 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); }