summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-13 13:03:08 -0400
committerJim Hahn <jrh3@att.com>2020-04-13 14:25:51 -0400
commitc0f026f3a76aae967101755978e03770182efff1 (patch)
tree7191c5438caa0d3e3f940266b7654598dffba5d0
parent784c32b3f2bcc26a0af719cb7f5e7ac75ebf9641 (diff)
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 <jrh3@att.com>
-rw-r--r--gson/src/main/java/org/onap/policy/common/gson/MapDoubleAdapterFactory.java20
1 files changed, 16 insertions, 4 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..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 <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);
}