From c0f026f3a76aae967101755978e03770182efff1 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 13 Apr 2020 13:03:08 -0400 Subject: Fix handling of number fields Yaml This fix also impacts StandardCoder, allowing Map.class to be used as the target type instead of requiring LinkedHashMap.class. Note: still doesn't do any translation if Object.class is used, as there is no way to override GSON's handler for the Object type. Issue-ID: POLICY-2488 Change-Id: Ia7cd0c85dc5a2a9e93360fa1c8397531b8503f2d Signed-off-by: Jim Hahn --- .../policy/common/gson/MapDoubleAdapterFactory.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'gson/src/main/java') 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..575c41ee 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 @@ -51,24 +51,36 @@ public class MapDoubleAdapterFactory implements TypeAdapterFactory { } private boolean isMapType(TypeToken type) { - if (type.getRawType() != Map.class) { + if (!Map.class.isAssignableFrom(type.getRawType())) { return false; } + // only supports Map + + if (!(type.getType() instanceof ParameterizedType)) { + // untyped - assume the parameters are the correct type + return true; + } + Type[] actualParams = ((ParameterizedType) type.getType()).getActualTypeArguments(); - // only supports Map return (actualParams[0] == String.class && actualParams[1] == Object.class); } private boolean isListType(TypeToken type) { - if (type.getRawType() != List.class) { + if (!List.class.isAssignableFrom(type.getRawType())) { return false; } + // only supports List + + if (!(type.getType() instanceof ParameterizedType)) { + // untyped - assume the parameters are the correct type + return true; + } + Type[] actualParams = ((ParameterizedType) type.getType()).getActualTypeArguments(); - // only supports List return (actualParams[0] == Object.class); } -- cgit 1.2.3-korg