WSLITE: Building JSON REST Request from Map causes StackOverflowError
<p>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: </p>

<pre><code>    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
                    }

}   
</code></pre>

<p>The passed map comes from another class which is responsible for some transformation and building the map containing the data I want to post. </p>

<p>The maps is structured like this: </p>

<pre><code>    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 &lt;Item&gt; m_itemList = []


    class Item {
        def porperty1 = ""
        def porperty2 = ""
        def porperty3 = ""
    }
</code></pre>

<p>Using <code>JsonOutput.prettyPrint(JsonOutput.toJson(data))</code> prints a nice Json string representation to the console - everything looks as expected. </p>

<p>Now, passing 'data" map to the post-closure (the payload) raises a "java.lang.StackOverflowError" </p>

<p>Stack trace: </p>

<pre><code>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.&lt;init&gt;(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.&lt;init&gt;(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.&lt;init&gt;(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.&lt;init&gt;(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
at wslite.json.JSONObject.&lt;init&gt;(JSONObject.java:292)
at wslite.json.JSONObject.wrap(JSONObject.java:1606)
at wslite.json.JSONArray.&lt;init&gt;(JSONArray.java:173)
at wslite.json.JSONObject.wrap(JSONObject.java:1590)
at wslite.json.JSONObject.populateMap(JSONObject.java:1012)
...
...
...
</code></pre>

<p>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? </p>

<p>Thank you in advance for your contributions. </p>

<p>UPDATE / WORKAROUND SOLUTION: </p>

<p>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. </p>

<p>I now cunstruct the map using the JsonBuilder and parse the result (String) with the JsonSlurper, finally pass this to WSLITE's content builder. </p>