> + Type type = ownerType.getType();
> + if (ownerType.getRawType() != declaring || !(type instanceof
> ParameterizedType))
> + return null;
> + Type keyType = ((ParameterizedType)
> type).getActualTypeArguments()[0];
> + Type valueType = ((ParameterizedType)
> type).getActualTypeArguments()[1];
> + TypeAdapter<?> keyAdapter = gson.getAdapter(TypeToken.get(keyType));
> + TypeAdapter<?> valueAdapter =
> gson.getAdapter(TypeToken.get(valueType));
> + return newAdapter(keyAdapter, valueAdapter);
> + }
> +
> + @SuppressWarnings("unchecked")
> + protected <K, V, T> TypeAdapter<T> newAdapter(TypeAdapter<K>
> keyAdapter, TypeAdapter<V> valueAdapter) {
> + return (TypeAdapter<T>) new ImmutableMapTypeAdapter<K,
> V>(keyAdapter, valueAdapter);
> + }
> + }
> +
> private static final class MapTypeAdapter<K, V> extends
> TypeAdapter<Map<K, V>> {
The adapter needs to return the right type. As the adapters are implemented as
final classes, I couldn't just extend it
It might be possible to dry up, but it would require more refactoring.
I had some issues parametrizing it, so I didn't do it. However, it might be
possible to have the Map adapter extend the ImmutableMap one and then reuse
most of the functionality. I will give it a try tonight or tomorrow.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15497948