You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by Zack Shoylev <no...@github.com> on 2014/07/25 22:35:26 UTC
[jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Specifically making sure deserialization works properly.
You can merge this Pull Request by running:
git pull https://github.com/rackspace/jclouds immutable-map-gson
Or you can view, comment on it, or merge it online at:
https://github.com/jclouds/jclouds/pull/455
-- Commit Summary --
* Adds support for ImmutableMap in jclouds gson
-- File Changes --
M core/src/main/java/org/jclouds/json/config/GsonModule.java (81)
M core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java (43)
-- Patch Links --
https://github.com/jclouds/jclouds/pull/455.patch
https://github.com/jclouds/jclouds/pull/455.diff
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1440](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1440/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50420455
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1514](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1514/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50418871
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
+1 - looks good to me. Thanks, @zack-shoylev!
The 1.8.0 release is just about to kick off. If you'd really like to get these in, I could wait..?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50494433
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
> + 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
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1041](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1041/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50418347
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1513](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1513/) FAILURE
Looks like there's a problem with this pull request
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50412935
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -201,6 +206,18 @@ public String toString() {
> }
> }
>
> + public static class ImmutableMapDeserializer implements JsonDeserializer<ImmutableMap<?,?>> {
> + @Override
> + public ImmutableMap<?,?> deserialize(final JsonElement json, final Type type,
> + final JsonDeserializationContext context) throws JsonParseException
> + {
> + final Type type2 =
> + ParameterizedTypeImpl.make(Map.class, ((ParameterizedType) type).getActualTypeArguments(), null);
> + final Map<?,?> map = context.deserialize(json, type2);
> + return ImmutableMap.copyOf(map);
What is happening where we need an immutable map currently? We take the current result from the deserialization and copy it into a map?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15472187
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
Reopened #455.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#event-146489322
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
Merged to [master](https://git-wip-us.apache.org/repos/asf?p=jclouds.git;a=commit;h=231a60675eec70ff02a8b6cf027e38bccb264276)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50533377
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
Closed #455.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#event-146922768
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
Alright, I changed my approach for this PR based on the reviews and some additional experimenting.
Based the new code on the MapTypeAdapter: handles nulls consistently, and should also be more efficient. Also added a test.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50412841
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1423](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1423/) ABORTED
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50213847
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
Reopened #455.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#event-145841549
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1042](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1042/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50418349
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1445](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1445/) ABORTED
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50526772
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
> @@ -201,6 +206,18 @@ public String toString() {
> }
> }
>
> + public static class ImmutableMapDeserializer implements JsonDeserializer<ImmutableMap<?,?>> {
> + @Override
> + public ImmutableMap<?,?> deserialize(final JsonElement json, final Type type,
> + final JsonDeserializationContext context) throws JsonParseException
> + {
> + final Type type2 =
> + ParameterizedTypeImpl.make(Map.class, ((ParameterizedType) type).getActualTypeArguments(), null);
> + final Map<?,?> map = context.deserialize(json, type2);
> + return ImmutableMap.copyOf(map);
I think moving.
Here is the case:
In neutron, I have a domain object which contains an ImmutableMap collection, as most (probably all) collections we use should be. Currently (before this fix) the constructor will take a regular Map, and then use copyOf to instantiate the ImmutableMap.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15473746
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Ignasi Barrera <no...@github.com>.
Nice addition! A couple of things, though:
* Can we get rid of those import rearrangements?
* Could you add a unit test for this?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50261244
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
> @@ -88,7 +87,8 @@
> @Singleton
> Gson provideGson(TypeAdapter<JsonBall> jsonAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter,
> ByteArrayAdapter byteArrayAdapter, PropertiesAdapter propertiesAdapter, JsonAdapterBindings bindings,
> - OptionalTypeAdapterFactory optional, SetTypeAdapterFactory set, ImmutableSetTypeAdapterFactory immutableSet,
> + OptionalTypeAdapterFactory optional, SetTypeAdapterFactory set, ImmutableMapDeserializer immutableMap,
> + ImmutableSetTypeAdapterFactory immutableSet,
I am not completely convinced about the second point, but it seems it will be somewhat confusing either way anyways.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15480437
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> jclouds-java-7-pull-requests #1513 FAILURE
Some [weird Jenkins failure](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1513/console).
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50414269
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
> @@ -201,6 +206,18 @@ public String toString() {
> }
> }
>
> + public static class ImmutableMapDeserializer implements JsonDeserializer<ImmutableMap<?,?>> {
> + @Override
> + public ImmutableMap<?,?> deserialize(final JsonElement json, final Type type,
> + final JsonDeserializationContext context) throws JsonParseException
> + {
> + final Type type2 =
> + ParameterizedTypeImpl.make(Map.class, ((ParameterizedType) type).getActualTypeArguments(), null);
> + final Map<?,?> map = context.deserialize(json, type2);
> + return ImmutableMap.copyOf(map);
> we'll have a follow-up commit to remove the kind of copies in constructors that you're talking about..?
Yes!
I am still investigating maybe doing something similar to the MapTypeAdapter (to remove that inefficiency), but not done yet.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15492841
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1517](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1517/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50443407
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -88,7 +87,8 @@
> @Singleton
> Gson provideGson(TypeAdapter<JsonBall> jsonAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter,
> ByteArrayAdapter byteArrayAdapter, PropertiesAdapter propertiesAdapter, JsonAdapterBindings bindings,
> - OptionalTypeAdapterFactory optional, SetTypeAdapterFactory set, ImmutableSetTypeAdapterFactory immutableSet,
> + OptionalTypeAdapterFactory optional, SetTypeAdapterFactory set, ImmutableMapDeserializer immutableMap,
> + ImmutableSetTypeAdapterFactory immutableSet,
> I am not completely convinced about the second point, but it seems it will be somewhat confusing either way anyways.
My take would be that the class itself serves as a type adapter which does the adapting by deserializing JSON. So the latter is an "implementation detail" whilst the former describes the purpose of the class. But I'm also OK with `ImmutableMapDeserializer` if you really prefer that.
Irrespective of that, how do you feel about moving the argument until after all the TAFs?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15481964
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -201,6 +206,18 @@ public String toString() {
> }
> }
>
> + public static class ImmutableMapDeserializer implements JsonDeserializer<ImmutableMap<?,?>> {
> + @Override
> + public ImmutableMap<?,?> deserialize(final JsonElement json, final Type type,
> + final JsonDeserializationContext context) throws JsonParseException
> + {
> + final Type type2 =
> + ParameterizedTypeImpl.make(Map.class, ((ParameterizedType) type).getActualTypeArguments(), null);
> + final Map<?,?> map = context.deserialize(json, type2);
> + return ImmutableMap.copyOf(map);
Is there some way to do this without creating an intermediate map, e.g. by using an ImmutableMap.builder() and calling some other `context...` method in a loop for each entry? An intermediate map isn't _that_ expensive, I guess, but I assume this method will be called quite a lot..?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15439121
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1031](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1031/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50208666
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> + 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>> {
> I will give it a try tonight or tomorrow.
Ah, cool...thanks!
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15499069
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1040](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1040/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50418348
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -227,6 +227,26 @@ public void testImmutableSet() {
> assertEquals(resources, ImmutableSet.of(new Resource("i-foo", "foo"), new Resource("i-bar", "bar")));
> }
>
> + private Gson immutableMap = new GsonBuilder().registerTypeAdapterFactory(new ImmutableMapTypeAdapterFactory()).create();
> + private Type immutableMapType = new TypeToken<ImmutableMap<String, String>>() {
> + private static final long serialVersionUID = 1L;
[minor] Or remove these and add `@SuppressWarning("someNameOrOtherIveForgotten")`?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15531236
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1516](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1516/) FAILURE
Looks like there's a problem with this pull request
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50437407
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1444](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1444/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50445304
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
Closed #455.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#event-145841548
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
I was having some issues with this but this discussion was helpful:
http://stackoverflow.com/questions/13623175/deserialize-to-an-immutablemap-with-gson
This should also cover some of the details of what the problem is.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50201158
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1439](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1439/) UNSTABLE
Looks like there's a problem with this pull request
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50416802
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
Thanks, @zack-shoylev! A couple of minor comments, and agree that a unit test would be nice.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50340909
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1506](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1506/) ABORTED
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50252237
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
> @@ -201,6 +206,18 @@ public String toString() {
> }
> }
>
> + public static class ImmutableMapDeserializer implements JsonDeserializer<ImmutableMap<?,?>> {
> + @Override
> + public ImmutableMap<?,?> deserialize(final JsonElement json, final Type type,
> + final JsonDeserializationContext context) throws JsonParseException
> + {
> + final Type type2 =
> + ParameterizedTypeImpl.make(Map.class, ((ParameterizedType) type).getActualTypeArguments(), null);
> + final Map<?,?> map = context.deserialize(json, type2);
> + return ImmutableMap.copyOf(map);
I am not sure that is possible.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15471707
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1426](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1426/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50221476
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Zack Shoylev <no...@github.com>.
Closed #455.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#event-146489321
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1443](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1443/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50441512
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> + 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>> {
Waiddaminute...if I'm understanding this correctly, `MapTypeAdapter` _already_ [builds an immutable map](https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java#L299-309)? If that is correct, what is the difference here?
And if we **do** need a different adapter, is there any way to cut down on the duplication between IMTA/MTA and IMTAF/MTAF?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15496975
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -201,6 +206,18 @@ public String toString() {
> }
> }
>
> + public static class ImmutableMapDeserializer implements JsonDeserializer<ImmutableMap<?,?>> {
> + @Override
> + public ImmutableMap<?,?> deserialize(final JsonElement json, final Type type,
> + final JsonDeserializationContext context) throws JsonParseException
> + {
> + final Type type2 =
> + ParameterizedTypeImpl.make(Map.class, ((ParameterizedType) type).getActualTypeArguments(), null);
> + final Map<?,?> map = context.deserialize(json, type2);
> + return ImmutableMap.copyOf(map);
> I think moving.
OK. In that case, I'm fine with just getting this in ;-) Thanks for explaining!
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15473811
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Jeremy Daggett <no...@github.com>.
Nice change! What code depends on this ATM? I do like the idea of deserializing directly to an `ImmutableMap` ;)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50250992
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1512](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1512/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50418674
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -271,6 +271,13 @@ public FluentIterableTypeAdapterFactory() {
> }
> }
>
> + public static class ImmutableMapTypeAdapterFactory extends MapTypeAdapterFactory {
> +
> + public ImmutableMapTypeAdapterFactory() {
> + super(ImmutableMap.class);
> + }
> + }
> +
Look at that....very nice!! ;-)
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15531172
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1045](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1045/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50442768
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1034](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1034/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50219218
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by Andrew Phillips <no...@github.com>.
> @@ -88,7 +87,8 @@
> @Singleton
> Gson provideGson(TypeAdapter<JsonBall> jsonAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter,
> ByteArrayAdapter byteArrayAdapter, PropertiesAdapter propertiesAdapter, JsonAdapterBindings bindings,
> - OptionalTypeAdapterFactory optional, SetTypeAdapterFactory set, ImmutableSetTypeAdapterFactory immutableSet,
> + OptionalTypeAdapterFactory optional, SetTypeAdapterFactory set, ImmutableMapDeserializer immutableMap,
> + ImmutableSetTypeAdapterFactory immutableSet,
A minor on the naming and location:
* move the constructor arg to a position _after_ all the TypeAdapterFactories? At first glance I thought this new argument was a TAF like all the others
* I know it implements JsonDeserializer, but call it ImmutableMapTypeAdapter since we're going to register it as a type adapter?
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455/files#r15439119
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1044](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1044/) SUCCESS
This pull request looks good
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50442771
Re: [jclouds] Adds support for ImmutableMap in jclouds gson (#455)
Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1503](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1503/) ABORTED
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/455#issuecomment-50248026