I need help getting the value of a parameter by reflection.
I'm getting the following error:
Error: java.lang.IllegalArgumentException: Can not set java.lang.String field com.jglar.base.dto.BaseAuditDTO.transactionId to java.lang.Class
This is the code I am running:
Main:
public class ObjectUtils {
private ObjectUtils() {
}
public static Map<String, Object> getFieldNamesAndValues(final Object obj,
boolean publicOnly)
throws IllegalArgumentException, IllegalAccessException {
Class<? extends Object> c1 = obj.getClass();
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map2 = new HashMap<String, Object>();
Field[] fields = c1.getDeclaredFields();
for (Field ls : fields) {
String name = ls.getName();
ls.setAccessible(true);
Object value = ls.get(obj);
map.put(name, value);
if (name.equalsIgnoreCase("baseAuditDto")) {
try {
Class<? extends Object> c2 = ls.getType();
Field[] fieldw = c2.getDeclaredFields();
// System.out.println(c2.getField("value3"));
for (Field dd : fieldw) {
String name2 = dd.getName();
System.out.println(name2);
dd.setAccessible(true);
Object value2 = dd.get(c2);
// map2.put(name2, value2);
}
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
System.out.println(map2.get("transactionId"));
return map;
}
Error:
Error: java.lang.IllegalArgumentException: Can not set java.lang.String field com.jglar.base.dto.BaseAuditDTO.transactionId to java.lang.Class
Please help me.
Aucun commentaire:
Enregistrer un commentaire