I have been stuck with this problem for a while now. Couldn't find any solution so far. Basicall I am doing nothing out of the ordinary. I have a Method to configure and send a Rest Request using Wslite and this method accepts a map as payload to the closure of the clients' post method like this:
def postSomething(Map payload){
RESTClient client = new RESTClient("http://somedomain.com/path/")
return client.post( accept: ContentType.ANY,
headers: [ callTreeId: uuid, jwt: token ] )
{
json payload
}
}
The passed map comes from another class which is responsible for some transformation and building the map containing the data I want to post.
The maps is structured like this:
Map data =
[
country: "String1",
fulfillingStoreId: "String2",
customerId: "String3",
cardholderId: "String3",
deliveryDate: "String4",
deliveryAddressId: "String5",
serviceType: "String6",
paymentType: "String1",
source: "String7",
origin:
[
system: "String8",
id: "String9"
]
,
contactFirstName: "String10",
contactLastName: "String11",
contactPhoneNumber: "String12",
items: [m_itemList] //a list that holds instances of some item objects
]
def List <Item> m_itemList = []
class Item {
def porperty1 = ""
def porperty2 = ""
def porperty3 = ""
}
Using JsonOutput.prettyPrint(JsonOutput.toJson(data))
prints a nice Json string representation to the console - everything looks as expected.
Now, passing 'data" map to the post-closure (the payload) raises a "java.lang.StackOverflowError"
Stack trace:
Exception in thread "main" java.lang.StackOverflowError
at java.util.HashMap.getNode(Unknown Source)
at java.util.HashMap.get(Unknown Source)
at java.lang.ClassLoader.getPackage(Unknown Source)
at java.lang.Package.getPackage(Unknown Source)
at java.lang.Class.getPackage(Unknown Source)
at wslite.json.JSONObject.wrap(JSONObject.java:1595)
at wslite.json.JSONArray.<init>(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.<init>(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.<init>(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.<init>(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.<init>(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.<init>(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
...
...
...
I understand that the contentbuilder of the wslite client accepts a map and i have done it before with other (simpler) requests. So what might be the problem?
Thank you in advance for your contributions.
UPDATE / WORKAROUND SOLUTION:
So after some digging I figured to just re-slurp the built json with the JsonSlurper before passing it to the content building clossure since the "prettyPrinting" the map shows correct results. Voila! No more StackOverFlow Exception.
I now cunstruct the map using the JsonBuilder and parse the result (String) with the JsonSlurper, finally pass this to WSLITE's content builder.