From 5ad17ae3107d0ea15608cba5578a6901e32253d0 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Tue, 30 Apr 2024 15:55:16 -0300 Subject: [PATCH] Rest service response error code 400 when a SDT with Dictionary with Numeric Key is returned and the Dictionary was loaded using fromXML. A work around was implemented to let it work when a Set was made to the dictionary before fromXML Issue: 108200 --- .../main/java/com/genexus/util/GXHashMap.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/java/src/main/java/com/genexus/util/GXHashMap.java b/java/src/main/java/com/genexus/util/GXHashMap.java index da425d36b..1afc06071 100644 --- a/java/src/main/java/com/genexus/util/GXHashMap.java +++ b/java/src/main/java/com/genexus/util/GXHashMap.java @@ -15,11 +15,18 @@ public class GXHashMap extends HashMap { private static Logger log = org.apache.logging.log4j.LogManager.getLogger(GXHashMap.class); private static final ObjectMapper objectMapper = new ObjectMapper(); + private boolean isNumberKey = false; public void setHashMap(GXHashMap hashMap) { putAll(hashMap); } + public V put(K key, V value) { + if (key instanceof Number) + isNumberKey = true; + return super.put(key, value); + } + public boolean get(K key, V[] value) { if (containsKey(key)) { value[0] = get(key); @@ -78,9 +85,19 @@ public Type getOwnerType() { try { this.clear(); - this.putAll(objectMapper.readValue(json, objectMapper.getTypeFactory().constructType(type))); + HashMap fromJsonHashMap = objectMapper.readValue(json, objectMapper.getTypeFactory().constructType(type)); + if (!isNumberKey) + this.putAll(fromJsonHashMap); + else { + for (Map.Entry entry : fromJsonHashMap.entrySet()) { + K key = entry.getKey(); + V value = entry.getValue(); + + this.put((K) java.text.NumberFormat.getInstance().parse((String) key), value); + } + } } - catch (JsonProcessingException e) { + catch (Exception e) { log.error("Could not set Dictionary from json", e); } }