From 7ce3b73b87711d4d4f1b39703bf55f94f881d892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Thu, 28 Mar 2024 17:18:34 +0100 Subject: [PATCH] Replace the use of Gson's internal newParametrizedTypeWithOwner since this class is an internal one, it can be changed without notice. Replacing this with a simple implementation of ParameterizedType. --- .../suse/salt/netapi/utils/ClientUtils.java | 8 +-- .../netapi/utils/ParameterizedTypeImpl.java | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/suse/salt/netapi/utils/ParameterizedTypeImpl.java diff --git a/src/main/java/com/suse/salt/netapi/utils/ClientUtils.java b/src/main/java/com/suse/salt/netapi/utils/ClientUtils.java index c1accb224..9330be2e0 100644 --- a/src/main/java/com/suse/salt/netapi/utils/ClientUtils.java +++ b/src/main/java/com/suse/salt/netapi/utils/ClientUtils.java @@ -7,8 +7,6 @@ import java.lang.reflect.Type; import java.util.Scanner; -import static com.google.gson.internal.$Gson$Types.newParameterizedTypeWithOwner; - import com.suse.salt.netapi.client.SaltClient; /** @@ -61,11 +59,9 @@ public static String streamToString(InputStream inputStream) { * @param rawType the raw type * @param typeArguments the type arguments * @return the parameterized type object - * @see com.google.gson.internal.$Gson$Types#newParameterizedTypeWithOwner */ - public static ParameterizedType parameterizedType(Type ownerType, Type rawType, - Type... typeArguments) { - return newParameterizedTypeWithOwner(ownerType, rawType, typeArguments); + public static ParameterizedType parameterizedType(Type ownerType, Type rawType, Type... typeArguments) { + return new ParameterizedTypeImpl(ownerType, rawType, typeArguments); } /** diff --git a/src/main/java/com/suse/salt/netapi/utils/ParameterizedTypeImpl.java b/src/main/java/com/suse/salt/netapi/utils/ParameterizedTypeImpl.java new file mode 100644 index 000000000..3f55c67aa --- /dev/null +++ b/src/main/java/com/suse/salt/netapi/utils/ParameterizedTypeImpl.java @@ -0,0 +1,50 @@ +package com.suse.salt.netapi.utils; + +import java.lang.reflect.Type; + +/** Implementation of Java's ParametrizedType for internal use */ +public class ParameterizedTypeImpl implements java.lang.reflect.ParameterizedType { + + private final Type owner; + private final Type raw; + private final Type[] argumentsTypes; + + /** + * Construct a parametrized type + * + * @param ownerIn the ownerIn type + * @param rawTypeIn the raw type + * @param argumentsTypesIn the arguments actual types + */ + public ParameterizedTypeImpl(Type ownerIn, Type rawTypeIn, Type[] argumentsTypesIn) { + owner = ownerIn; + raw = rawTypeIn; + argumentsTypes = argumentsTypesIn; + } + + /** + * Construct a parametrized type for a single argument + * + * @param ownerIn the ownerIn type + * @param rawTypeIn the raw type + * @param argumentTypeIn the argument actual types + */ + public ParameterizedTypeImpl(Type ownerIn, Type rawTypeIn, Type argumentTypeIn) { + this(ownerIn, rawTypeIn, new Type[]{argumentTypeIn}); + } + + @Override + public Type[] getActualTypeArguments() { + return argumentsTypes; + } + + @Override + public Type getRawType() { + return raw; + } + + @Override + public Type getOwnerType() { + return owner; + } +}