From 9d731d0153175c0d3951b82d4f63d33c6b593b9b Mon Sep 17 00:00:00 2001 From: acetousk Date: Fri, 23 Aug 2024 16:33:49 -0600 Subject: [PATCH 1/2] Add flattenNestedMapWithKeys method for stripe conversion to application/x-www-form-urlencoded --- .../org/moqui/util/CollectionUtilities.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/framework/src/main/java/org/moqui/util/CollectionUtilities.java b/framework/src/main/java/org/moqui/util/CollectionUtilities.java index 3252956a8..ea7fe9459 100644 --- a/framework/src/main/java/org/moqui/util/CollectionUtilities.java +++ b/framework/src/main/java/org/moqui/util/CollectionUtilities.java @@ -460,6 +460,39 @@ public static Map flattenNestedMap(Map theMap) { return outMap; } + public static Map flattenNestedMapWithKeys(Map theMap) { + return flattenNestedMapWithKeys(theMap, ""); + } + + @SuppressWarnings("unchecked") + private static Map flattenNestedMapWithKeys(Map theMap, String parentKey) { + Map output = new LinkedHashMap<>(); + + if (theMap == null) return output; + + for (Map.Entry 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) value, newKey)); + } else if (value instanceof Collection) { + int index = 0; + for (Object colValue : (Collection) value) { + if (colValue instanceof Map) { + output.putAll(flattenNestedMapWithKeys((Map) 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 baseMap, Map overrideMap, boolean overrideEmpty) { if (baseMap == null || overrideMap == null) return; From 8a80efca616a6ebad002e8eca323bd8f9f84639d Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Sat, 26 Oct 2024 08:57:06 +0700 Subject: [PATCH 2/2] fix: Unable to release Session : Caused by: java.io.NotSerializableException: org.apache.groovy.json.internal.LazyMap --- framework/src/main/java/org/moqui/util/RestClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/org/moqui/util/RestClient.java b/framework/src/main/java/org/moqui/util/RestClient.java index 46b389f7c..b2603bad9 100644 --- a/framework/src/main/java/org/moqui/util/RestClient.java +++ b/framework/src/main/java/org/moqui/util/RestClient.java @@ -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; @@ -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); }