diff --git a/src/client.ts b/src/client.ts index 2996d9ef9..2a138ac19 100644 --- a/src/client.ts +++ b/src/client.ts @@ -188,6 +188,10 @@ export class Client extends EventEmitter { } } } + + if(options.overrideElementKey !== undefined) { + this.wsdl.options.overrideElementKey = options.overrideElementKey; + } if (options.overrideRootElement !== undefined) { this.wsdl.options.overrideRootElement = options.overrideRootElement; } diff --git a/src/types.ts b/src/types.ts index a48d476f3..4e4b3bfde 100644 --- a/src/types.ts +++ b/src/types.ts @@ -89,6 +89,7 @@ export interface IWsdlBaseOptions { valueKey?: string; xmlKey?: string; overrideRootElement?: { namespace: string; xmlnsAttributes?: IXmlAttribute[]; }; + overrideElementKey?: Object ignoredNamespaces?: boolean | string[] | { namespaces?: string[]; override?: boolean; }; ignoreBaseNameSpaces?: boolean; /** escape special XML characters in SOAP message (e.g. &, >, < etc), default: true. */ diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts index 9bc74ff08..0a4657baa 100644 --- a/src/wsdl/index.ts +++ b/src/wsdl/index.ts @@ -637,6 +637,17 @@ export class WSDL { public objectToXML(obj, name: string, nsPrefix: any, nsURI: string, isFirst?: boolean, xmlnsAttr?, schemaObject?, nsContext?: NamespaceContext) { const schema = this.definitions.schemas[nsURI]; + if(this.options.overrideElementKey && Object.keys(this.options.overrideElementKey).length > 0) { + for (let key in this.options.overrideElementKey) { + const overrideKey = this.options.overrideElementKey[key]; + if (obj && obj[key]) { + Object.defineProperty(obj, overrideKey, + Object.getOwnPropertyDescriptor(obj, key)); + delete obj[key]; + } + } + } + let parentNsPrefix = nsPrefix ? nsPrefix.parent : undefined; if (typeof parentNsPrefix !== 'undefined') { // we got the parentNsPrefix for our array. setting the namespace-variable back to the current namespace string @@ -1175,6 +1186,9 @@ export class WSDL { this.options.forceSoap12Headers = options.forceSoap12Headers; this.options.customDeserializer = options.customDeserializer; + if(options.overrideElementKey !== undefined) { + this.options.overrideElementKey = options.overrideElementKey; + } if (options.overrideRootElement !== undefined) { this.options.overrideRootElement = options.overrideRootElement; }