Skip to content
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

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

snburkett
Copy link
Contributor

@snburkett snburkett commented Jan 7, 2018

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>

@coveralls
Copy link

coveralls commented Jan 7, 2018

Coverage Status

Coverage increased (+0.02%) to 93.664% when pulling c053845 on SpryDigital:arrayElementNamespacing into 0eec713 on vpulim:master.

@jsdevel
Copy link
Collaborator

jsdevel commented Jan 8, 2018

Looks good to me (cc @herom). @snburkett can you add a note in the README?

lib/wsdl.js Outdated
if (options.namespaceArrayElements !== undefined) {
this.options.namespaceArrayElements = options.namespaceArrayElements;
}
else {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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 ===

@coveralls
Copy link

coveralls commented Jan 8, 2018

Coverage Status

Coverage increased (+0.02%) to 93.664% when pulling 717aafd on SpryDigital:arrayElementNamespacing into 0eec713 on vpulim:master.

add tests for array element namespacing options
@coveralls
Copy link

coveralls commented Jan 8, 2018

Coverage Status

Coverage increased (+0.02%) to 93.664% when pulling 8c995c7 on SpryDigital:arrayElementNamespacing into 0eec713 on vpulim:master.

@snburkett
Copy link
Contributor Author

Readme updated and code style changes made. Squashed/forced into the original commit. Please let me know if you need anything else. Thank you!

@herom herom merged commit f6253a7 into vpulim:master Jan 9, 2018
@herom
Copy link
Contributor

herom commented Jan 9, 2018

Thanks a ton @snburkett 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants