private static void getSrcALLFieldMap(Object obj,MapcollectMap){
Class srcClazz=obj.getClass();
Field[] srcFields=srcClazz.getDeclaredFields();
Stream.of(srcFields).forEach(field->{
field.setAccessible(true);try{if(field.getType().toString().contains("aacoin.account") && !field.getType().isEnum()){
Object subObj=field.get(obj);if(subObj!=null)
getSrcALLFieldMap(subObj,collectMap);
}else{
collectMap.put(field.getName(),field.get(obj));
}
}catch(IllegalAccessException e) {
e.printStackTrace();
}
});
}private static void setTargetAllField(Object obj, MapsrcMap){
Class srcClazz=obj.getClass();
Field[] srcFields=srcClazz.getDeclaredFields();
Stream.of(srcFields).forEach(field->{
field.setAccessible(true);try{if(field.getType().toString().contains("aacoin.trade.otc") && !field.getType().isEnum()){
Object subObj=field.get(obj);if(subObj == null) {
Constructor cons= field.getType().getDeclaredConstructor(null);
cons.setAccessible(true);
subObj= cons.newInstance(null);
field.set(obj, subObj);
}
setTargetAllField(subObj, srcMap);
}else{//collectMap.put(field,obj);
Object currentField =srcMap.get(field.getName());if( currentField !=null && field.getType() ==currentField.getClass()){
field.set(obj,currentField);
}
}
}catch(IllegalAccessException e) {
e.printStackTrace();
}catch(InstantiationException e) {
e.printStackTrace();
}catch(NoSuchMethodException e) {
e.printStackTrace();
}catch(InvocationTargetException e) {
e.printStackTrace();
}
});
}public static T convert(Object src,ClasstClass){
Constructor cons = null;try{
cons= tClass.getDeclaredConstructor(null);
}catch(NoSuchMethodException e) {
e.printStackTrace();
}
cons.setAccessible(true);
T result= null;try{
result= cons.newInstance(null);
}catch(InstantiationException e) {
e.printStackTrace();
}catch(IllegalAccessException e) {
e.printStackTrace();
}catch(InvocationTargetException e) {
e.printStackTrace();
}
convert(src,result);returnresult;
}public static T convert(Object src,T result) {
Map srcMap = newHashMap();
getSrcALLFieldMap(src,srcMap);
setTargetAllField(result,srcMap);returnresult;
}