public <T> MyBinder<T> create(Class<T> clazz) { if (clazz == null) { throw new IllegalArgumentException("Invalid class"); } if (clazz.isPrimitive() || MyBinder.isWrapperType(clazz)) { throw new IllegalArgumentException("Invalid class"); } checkSerializable(clazz); if (binders.containsKey(clazz)) { return binders.get(clazz); } MyBinder<T> binder = new MyBinder<T>(clazz); binders.put(clazz, binder); return binder; }
private void checkSub(Set<Class<?>> checked, Class<?> clazz) { if (clazz.isPrimitive() || clazz.equals(String.class) || clazz.isEnum()) { return; } if (clazz.isArray() || MyBinder.isWrapperType(clazz)) { throw new IllegalArgumentException("The class can't be serialized"); } if (checked.contains(clazz)) { return; } checkDefaultConstructor(clazz); checked.add(clazz); for (Field field : clazz.getDeclaredFields()) { if (field.getAnnotation(DoNotBind.class) != null) { continue; } checkSub(checked, field.getType()); } }