Fix handling of number fields Yaml 56/105856/1
authorJim Hahn <jrh3@att.com>
Mon, 13 Apr 2020 17:03:08 +0000 (13:03 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 13 Apr 2020 18:25:51 +0000 (14:25 -0400)
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 <jrh3@att.com>
gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java

index bd03199..575c41e 100644 (file)
@@ -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);
     }