In Gson 2.8.5, the JavaDoc to TypeAdapterFactory presents a code sample of MultisetTypeAdapterFactory. However, this code sample does not work (instead of MultisetTypeAdapterFactory, CollectionTypeAdapterFactory is triggered). The problem is in these lines:
if (typeToken.getRawType() != Multiset.class || !(type instanceof ParameterizedType)) {
return null;
}
Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
Instead, the following should be used (like in CollectionTypeAdapterFactory):
Class<? super T> rawType = typeToken.getRawType();
if (!Multiset.class.isAssignableFrom(rawType)) {
return null;
}
Type elementType = $Gson$Types.getCollectionElementType(type, rawType);
In Gson 2.8.5, the JavaDoc to
TypeAdapterFactorypresents a code sample ofMultisetTypeAdapterFactory. However, this code sample does not work (instead ofMultisetTypeAdapterFactory,CollectionTypeAdapterFactoryis triggered). The problem is in these lines:Instead, the following should be used (like in
CollectionTypeAdapterFactory):