Nov 06, 2014 19:31
public static T setDefaultValues(T object) {
for (Field f : object.getClass().getDeclaredFields()) {
f.setAccessible(true);
try {
if (String.class.isAssignableFrom(f.getType())) {
f.set(object, f.getName());
} else if (XMLGregorianCalendar.class.isAssignableFrom(f.getType())) {
XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar((new GregorianCalendar()));
f.set(object, xmlGregorianCalendar);
} else if (BigDecimal.class.isAssignableFrom(f.getType())) {
f.set(object, new BigDecimal(Math.random()));
}
else if (List.class.isAssignableFrom(f.getType())){
ParameterizedType stringListType = (ParameterizedType) f.getGenericType();
Class stringListClass = (Class) stringListType.getActualTypeArguments()[0];
Object o = setDefaultValues(stringListClass.newInstance());
ArrayList
рекурсия,
ояебу. многораз