How can I use Jsonix in Google Apps Script (server side Google Docs automation)? If I can't, what's an alternate to Jsonix I can use in GAS to generate Javascript mappings from XSD, then serialize a JS object to XML for submission to a REST API, then deserialize the response back into a JS object?
I used Jsonix to compile a REST API from its XSD files to JSON mappings. I tested OK in commandline Node.js a Javascript that creates a JS object from inline JSON, then marshals it under the Jsonix.Context for submisstion to the REST API, then unmarshals the response.
Then I created a Google Apps Script project with my script. I created another GAS project with the Jsonix.js script (as Jsonix.gs), then another GAS project with the mappings script (as API.gs). I configured my main script's project Resources with the Jsonix and API libraries' project keys. I can execute my script (verifying the library resources are used), but it fails when Jsonix.createDocument()
is called. I inserted into the beginning of the Jsonix library script's _jsonix_factory = function(_jsonix_xmldom, _jsonix_xmlhttprequest, _jsonix_fs)
a Logger.log("_jsonix_xmldom: " + _jsonix_xmldom)
line that logs _jsonix_xmldom: undefined
, which is why Jsonix.createDocument()
throws an error instead of returning a document.
Can I use the Google Apps Script service XmlService, or some other service in the GAS environment, instead of the _jsonix_xmldom that Jsonix expects by default? Or can I include as a library resource some functionally equivalent libraries? Or otherwise supply that functionality to Jsonix in GAS?
I expect that similar errors will result from Jsonix trying to use the _jsonix_xmlhttprequest
and _jsonix_fs
values that are also undefined. I see in the Jsonix.js (.gs) source code the two lines
// REWORK
// Node.js
in the createDocument()
declaration and elsewhere. Perhaps this case I'm reporting is in active development?
Thanks for your insights.