diff options
Diffstat (limited to 'gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java')
-rw-r--r-- | gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java b/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java index bd031999..057e97f8 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java +++ b/gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,24 +51,36 @@ public class MapDoubleAdapterFactory implements TypeAdapterFactory { } private <T> boolean isMapType(TypeToken<T> type) { - if (type.getRawType() != Map.class) { + if (!Map.class.isAssignableFrom(type.getRawType())) { return false; } + // only supports Map<String,Object> + + if (!(type.getType() instanceof ParameterizedType)) { + // untyped - assume the parameters are the correct type + return true; + } + Type[] actualParams = ((ParameterizedType) type.getType()).getActualTypeArguments(); - // only supports Map<String,Object> return (actualParams[0] == String.class && actualParams[1] == Object.class); } private <T> boolean isListType(TypeToken<T> type) { - if (type.getRawType() != List.class) { + if (!List.class.isAssignableFrom(type.getRawType())) { return false; } + // only supports List<Object> + + if (!(type.getType() instanceof ParameterizedType)) { + // untyped - assume the parameters are the correct type + return true; + } + Type[] actualParams = ((ParameterizedType) type.getType()).getActualTypeArguments(); - // only supports List<Object> return (actualParams[0] == Object.class); } @@ -100,7 +112,7 @@ public class MapDoubleAdapterFactory implements TypeAdapterFactory { @Override public T read(JsonReader in) throws IOException { - T value = delegate.read(in); + var value = delegate.read(in); DoubleConverter.convertFromDouble(value); |