Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main sync #24

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
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
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