private Object toObject(Object value, String type, ClassLoader cl) throws ClassNotFoundException, IOException { if (type != null && type.equals(NULL)) { return null; } if (value == null) return MCast.getDefaultPrimitive(type); if (type != null && type.equals(SERIALISED)) { return MCast.unserializeFromString(String.valueOf(value), cl); } Class<?> t = cl.loadClass(type); return MCast.toType(value, t, null); }
@SuppressWarnings("unchecked") @Override public void set(Object pojo, T value) throws IOException { if (!writable) throw new IOException("field is read only: " + name); try { pojo = PojoParser.checkParent(parent,pojo); if (!field.isAccessible()) field.setAccessible(true); value = (T) MCast.toType(value, getType(), null); if (getType().isPrimitive() && value == null) { // that's not possible value = (T)MCast.getDefaultPrimitive(getType()); } field.set(pojo, value); } catch (Exception e) { throw new IOException(field.getName(),e); } }
@SuppressWarnings("unchecked") @Override public void set(Object pojo, T value) throws IOException { pojo = PojoParser.checkParent(parent,pojo); if (setter == null) throw new IOException("Method is read only: " + getter.getName()); // if (!getType().isInstance(pojo)) // throw new IOException("Object is not instance of " + getType().getCanonicalName()); try { value = (T) MCast.toType(value, getType(), null); if (getType().isPrimitive() && value == null) { // that's not possible value = (T)MCast.getDefaultPrimitive(getType()); } setter.invoke(pojo, value); } catch (Exception e) { throw new IOException("Error set: " + name + "(" + getType() + ")=" + value, e); } }