Question

I'm using the Java client library for the Directory API from here: https://developers.google.com/api-client-library/java/apis/admin/directory_v1

The com.google.api.services.admin.directory.model.User model has changed from 1.16 to 1.19.

In the old version I used to be able to do this:

List<UserAddress> userAddressList = user.getAddresses();
for(UserAddress userAddress : userAddressList) {
    ///
}

But now user.getAddresses is returning an Object. Same deal for getOrganizations, phones, etc... These all return an Object which upon further inspection looks like:

List<ArrayMap<String, String>>

ArrayMap extends GenericJson.

What do I have to do to get at the UserAddress, other then going back to the previous version?

Was it helpful?

Solution

It's a bug (from my point of view) in the latest versions. Use an older one like 1.16, 1.17 or the first 1.18 (latest 1.18 also have the bug).

OTHER TIPS

The same thing happened in the C# client and back in May 2015 a Google developer named Eric Koleda replied:

A change to the backend had the unintended consequence of changing the discovery document for the service, making the addresses field (and others) being marked as type=any. This causes problems for strongly types languages like .NET, as you've found. The team is aware of the issue but it's unclear when a fix will be available.

However the C# client still has this problem, so I would assume the Java client does as well.

Here are a couple of issues I found in Google's issue tracker specifically for this problem in the Java client, but neither has seen any progress yet:

  • Issue 3645: Broken code generator for Directory API in Java client: User class lacking explicit types
  • Issue 3730: Latest version of the Directory API client returns Object instead of correct class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top