I´m trying to use reflection to get all the fields from PostExper class which are defined as (Map) and add them to a similar map declared in another class any help is welcomed
While executing the next I end up with
"Method threw java.lang.IllegalArgumentException' exception."
java.lang.IllegalArgumentException: Can not set java.util.Map field EndpointRequests.LegacyEndpoints.PostExpertManagerActionRequest.param_form_id to EndpointRequests.LegacyEndpoints.PostExpertManagerActionRequest$16
suppressedExceptions = {Collections$UnmodifiableRandomAccessList@3587} size = 0
public class PostExper {
//attributes
Map<String,String> header_connection=new HashMap<String,String>();
Map<String,String> header_cacheControl=new HashMap<String,String>();
}
//method snipped used
Class pExMAcReq = PostExpert.class;
try {
Field[] fields = pExMAcReq.getDeclaredFields();
for(Field f:fields){
if(f.getName().startsWith(prefix)){
Map<String,String> instance = new HashMap<String,String>();
Object res = f.get(instance); //Exception instance is not writeable
map.putAll(res);
}
}
}catch(Throwable e){}
Aucun commentaire:
Enregistrer un commentaire