strong-soap
strong-soap copied to clipboard
jsonToXml don't serialize Date value as ISO8601 format.
I found strong-soap's XMLHandler use toString, not toISOString for serializing xsd:dateTime value in request arguments.
I think string format for xsd:dateTime is ISO8601. (format: [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm])
http://books.xmlschemata.org/relaxng/ch19-77049.html
Here is my sample code:
var handler = new soap.XMLHandler();
var node = handler.jsonToXml(null, null, soap.XMLHandler.createSOAPEnvelopeDescriptor("soap"), {"date": new Date()});
var xml = node.end({pretty: true});
console.log(xml);
Expect:
<date>2017-04-18T15:24:26.871Z</date>
Actual:
<date>Wed Apr 19 2017 00:24:26 GMT+0900 (JST)</date>
Affects me too.
The problem is the toString method on a Date object. The Date object is used for xsd:datetime: https://github.com/strongloop/strong-soap/blob/09b1cfdd9582a592874c09fa47f5f301d2ed2ae2/src/parser/helper.js#L11-L13

Overriding the toString on Date should work. Investigating now.
We ended up forking Strong-SOAP and changing from Date to a String. This ended up being the desired behaviour for us.
However, the following could be useful for someone else:
function ISODate(value) {
ISODate.toString = function() {
return new Date(value).toISOString();
};
}
Then at https://github.com/strongloop/strong-soap/blob/09b1cfdd9582a592874c09fa47f5f301d2ed2ae2/src/parser/helper.js#L11-L13 :
- dateTime: Date,
- time: Date,
- date: Date,
+ dateTime: ISODate,
+ time: ISODate,
+ date: ISODate,
Please create a patch to use your technique or fix https://github.com/strongloop/strong-soap/blob/master/src/parser/xmlHandler.js#L164.