@Test(expected=JSON.DataException.class) public void testGetAsMissingKey() throws JSON.DataException { final Map<String,Object> json = new HashMap<String,Object>(); final String key = "foo"; JSON.getAs(json, key, String.class); }
public static <T> T getAs(Map<String,Object> json, String key, Class<T> type) throws DataException { final Object o = getNonNull(json, key); if (!type.isInstance(o)) { throw new DataException( key + " == " + o + ", a " + o.getClass().getName() + ", expected a " + type.getName()); } return type.cast(o); }
JSON { public static <T> T getAs(Map<String,Object> json, String key, Class<T> type) throws DataException { final Object o = getNonNull(json, key); if (!type.isInstance(o)) { throw new DataException( key + " == " + o + ", a " + o.getClass().getName() + ", expected a " + type.getName()); } return type.cast(o); } }
JSON { public static <T> T getAs(Map<String,Object> json, String key, Class<T> type) throws DataException { final Object o = getNonNull(json, key); if (!type.isInstance(o)) { throw new DataException( key + " == " + o + ", a " + o.getClass().getName() + ", expected a " + type.getName()); } return type.cast(o); } protected  JSON(); }
JSON { public static <T> T getAs(Map<String,Object> json, String key, Class<T> type) throws DataException { final Object o = getNonNull(json, key); if (!type.isInstance(o)) { throw new DataException( key + " == " + o + ", a " + o.getClass().getName() + ", expected a " + type.getName()); } return type.cast(o); } protected  JSON(); static T getAs(Map<String,Object> json, String key, Class<T> type); static Object getNonNull(Map<String,Object> json, String key); }
JSON { public static <T> T getAs(Map<String,Object> json, String key, Class<T> type) throws DataException { final Object o = getNonNull(json, key); if (!type.isInstance(o)) { throw new DataException( key + " == " + o + ", a " + o.getClass().getName() + ", expected a " + type.getName()); } return type.cast(o); } protected  JSON(); static T getAs(Map<String,Object> json, String key, Class<T> type); static Object getNonNull(Map<String,Object> json, String key);  }