Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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