loopbackio / strong-soap

SOAP driver for Node.js (A complete rewrite of node-soap)
Other
391 stars 159 forks source link

jsonToXml don't serialize Date value as ISO8601 format. #94

Open mtgto opened 7 years ago

mtgto commented 7 years ago

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>
vasyas commented 7 years ago

Affects me too.

Glavin001 commented 6 years ago

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

image

Overriding the toString on Date should work. Investigating now.

Glavin001 commented 6 years ago

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, 
raymondfeng commented 6 years ago

Please create a patch to use your technique or fix https://github.com/strongloop/strong-soap/blob/master/src/parser/xmlHandler.js#L164.