-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add option to remove element-by-element namespacing of json arrays #994
Conversation
Looks good to me (cc @herom). @snburkett can you add a note in the |
lib/wsdl.js
Outdated
if (options.namespaceArrayElements !== undefined) { | ||
this.options.namespaceArrayElements = options.namespaceArrayElements; | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please move the else
up, so that it's in line with the closing brace of the if
condition (} else {
)?
lib/wsdl.js
Outdated
@@ -1718,9 +1725,13 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns | |||
parts.push(openingTagParts.join('')); | |||
} else { | |||
openingTagParts.push('>'); | |||
parts.push(openingTagParts.join('')); | |||
if(self.options.namespaceArrayElements || i == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just use the "typesafe" operator ===
only
lib/wsdl.js
Outdated
parts.push(body); | ||
parts.push(['</', appendColon(correctOuterNsPrefix), name, '>'].join('')); | ||
if(self.options.namespaceArrayElements || i == n-1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as above, please just use ===
add tests for array element namespacing options
717aafd
to
8c995c7
Compare
Readme updated and code style changes made. Squashed/forced into the original commit. Please let me know if you need anything else. Thank you! |
Thanks a ton @snburkett 🚀 |
By default the wsdl marshalling code converts JSON arrays of the form:
{ PeriodList: { PeriodType: [ {PeriodId: '1'}, {PeriodId: '2'} ] } }
Into xml documents of the form
<PeriodList> <PeriodType><PeriodId>1</PeriodId></PeriodType><PeriodType><PeriodId>2</PeriodId></PeriodType></PeriodList>
However, certain web services are unable to correctly recognize that the various "PeriodType" elements are intended to be part of the same array, resulting in the unmarshalling:
{ PeriodList: [ PeriodType: [ {PeriodId: '1'} ], PeriodType: [ {PeriodId: '2'} ] ] }
To remedy this, a new client/wsdl option "namespaceArrayElements" has been added. The default (true) is the current behavior. If namespaceArrayElements is set to false, however, the following xml will be generated, which allows for correct array construction on the server side:
<PeriodList><PeriodType><PeriodId>1</PeriodId><PeriodId>2</PeriodId></PeriodType></PeriodList>