When calling a Web service with the interface defined as follows:


service UploadData {
resource upload(login : Login, ritten : Collection) : JSON {
uri = “/uploadDataServlet”
+ “&userName=” + escape(login.userName)
+ “&password=” + escape(mobl::crypto::sha1(login.password))
method = “POST”
encoding = “json”
data = JSON.stringify(ritten)
}
}

(in which Rit is a simple Entity having only attributes and not references), then a JS error “Uncaught TypeError: Converting circular structure to JSON” occurs which seems to originate in the mobl JS library (or one of them).

When coercing ‘ritten’ into an Array using .list(), the sync->async transformation seems to fail as the generated JS code reads “data: mobl.JSON.stringify(ritten.list())” and a JS error ensues because list() has been called without an async callback.

Submitted by Meinte Boersma on 14 March 2011 at 22:49

On 15 March 2011 at 13:00 Zef Hemel tagged @zefhemel

On 16 March 2011 at 16:13 Meinte Boersma commented:

Workaround, as suggested by Zef:

Listify outside of the service, like so:

service UploadData {
    resource upload(login : Login, ritten : [Rit]) : JSON {
        uri = "/uploadDataServlet"
        method = "POST"
        encoding = "json"
        data = JSON.stringify(ritten)
    }
}

Call:

var ritten = (Rit.all() order by beginstand asc).list();
UploadData.upload(login1, ritten);

Note that you have to use the intermediate var here, as with ritten inlined into the call, a JS error still ensues (didn’t really look into that).

Log in to post comments