mardi 26 juillet 2016

How can I know the last object when I reflect?

I have a DTO like this,

ADto{
  BDto bDto;
  Cto cDto;
}

BDto{
  String a1;
  String b1;
  int b1;
}

CDto{
  String a2;
  String b2;
  int b2;
}

When I use reflect,I want to get the BDto and CDto in ADto Object.Code like this:

 for (Field field : aObj.getClass().getDeclaredFields()) {
            try {
                Object fieldValue = field.get(object);
 //todo  how to collect all String value  in `BDto` and `CDto` of aObj
                if (fieldValue instanceof String) {
                    shouldCheckFieldValues.add((String) fieldValue);
                }
            } catch (Exception e) {
                logger.error("some error has happened when fetch data in loop", e);
            }

        }
    }

I want to collect all String value in BDto and CDto of aObj?How can I achieve this? Or how can I know the field which I have to recursive traversal with no hard code?





Aucun commentaire:

Enregistrer un commentaire