Skip to content

Commit

Permalink
Merge branch 'moqui:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dixitdeepak authored Dec 2, 2024
2 parents f24d4a5 + 60dd57c commit e29dd4e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions framework/src/main/java/org/moqui/util/CollectionUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,39 @@ public static Map flattenNestedMap(Map theMap) {
return outMap;
}

public static Map<String, String> flattenNestedMapWithKeys(Map<String, Object> theMap) {
return flattenNestedMapWithKeys(theMap, "");
}

@SuppressWarnings("unchecked")
private static Map<String, String> flattenNestedMapWithKeys(Map<String, Object> theMap, String parentKey) {
Map<String, String> output = new LinkedHashMap<>();

if (theMap == null) return output;

for (Map.Entry<String, Object> entry : theMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String newKey = parentKey.isEmpty() ? key : parentKey + "[" + key + "]";

if (value instanceof Map) {
output.putAll(flattenNestedMapWithKeys((Map<String, Object>) value, newKey));
} else if (value instanceof Collection) {
int index = 0;
for (Object colValue : (Collection<?>) value) {
if (colValue instanceof Map) {
output.putAll(flattenNestedMapWithKeys((Map<String, Object>) colValue, newKey + "[" + index + "]"));
} else {
output.put(newKey + "[" + index + "]", colValue.toString());
}
index++;
}
} else {
output.put(newKey, value.toString());
}
}
return output;
}
@SuppressWarnings("unchecked")
public static void mergeNestedMap(Map<Object, Object> baseMap, Map<Object, Object> overrideMap, boolean overrideEmpty) {
if (baseMap == null || overrideMap == null) return;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/java/org/moqui/util/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package org.moqui.util;

import groovy.json.JsonBuilder;
import groovy.json.JsonSlurper;
import groovy.json.JsonSlurperClassic;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.client.HttpResponseException;
Expand Down Expand Up @@ -442,7 +442,7 @@ public String text() {
/** Parse the response as JSON and return an Object */
public Object jsonObject() {
try {
return new JsonSlurper().parseText(text());
return new JsonSlurperClassic().parseText(text());
} catch (Throwable t) {
throw new BaseException("Error parsing JSON response from request to " + rci.uriString, t);
}
Expand Down

0 comments on commit e29dd4e

Please sign in to comment.