Skip to content

Commit

Permalink
Rest service response error code 400 when a SDT with Dictionary with …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
iroqueta committed Apr 30, 2024
1 parent bf90ec1 commit 5ad17ae
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions java/src/main/java/com/genexus/util/GXHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
public class GXHashMap<K, V> extends HashMap<K, V> {
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<K, V> 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);
Expand Down Expand Up @@ -78,9 +85,19 @@ public Type getOwnerType() {

try {
this.clear();
this.putAll(objectMapper.readValue(json, objectMapper.getTypeFactory().constructType(type)));
HashMap<K, V> fromJsonHashMap = objectMapper.readValue(json, objectMapper.getTypeFactory().constructType(type));
if (!isNumberKey)
this.putAll(fromJsonHashMap);
else {
for (Map.Entry<K, V> 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);
}
}
Expand Down

0 comments on commit 5ad17ae

Please sign in to comment.