Google Directory User
object returned by Google has name
attribute rightly as UserName
object but emails
attribute is of type ArrayList of E' and email properties are present as an ArrayMap in the first member of this list instead of coming as a
UserEmail' object strangely.
In my case, I get to decide the type of attribute only run-time and hence I'm using Java Reflection as below.
String outerGetter = "get" + outerParam;
List<Object> outerValues = (List<Object>)ReflectionUtils.get(user, outerGetter);
if(outerValues == null){
return null;
}
String innerGetter = "get" + upperFirstLetter(attrName.substring(firstDotIndex + 1));
for(Object outerValue: outerValues){
JSONObject jo = new JSONObject();
Object innerValue = ReflectionUtils.get(outerValue, innerGetter);
if(innerValue == null){
return null;
}
jo.put(scimAttribute.subName, innerValue);
ja.put(jo);
}
ReflectionUtils.get(user, method)
basically executes method of user
and return Object
type.
For name
property : outerGetter
is getName
and innerGetter
is say getFamilyName
and it works fine.
But for emails
property : outerGetter
is getEmails
and innerGetter
is getAddress
and it gives NoSuchMethodException: com.google.api.client.util.ArrayMap.getAddress()
. getAddress()
is part of UserEmail
object and hence this exception I guess. Can anyone tell me why I'm not getting UserEmail
object in the first place?.
I'm new to Reflection as well as Google Directory APIs. Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire