rbeckman-nextgen / test-mc2

0 stars 0 forks source link

Add some options for controlling how the interop connectors convert XML to JSON #4307

Closed rbeckman-nextgen closed 5 years ago

rbeckman-nextgen commented 5 years ago

The interop connectors automatically convert XML to JSON. For example, an XML payload like this: `

urn:oid:2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.1^SOZyOX4vFREzOe4G

Will be converted to: { "@xmlns" : "urn:ihe:iti:xds-b:2007", "DocumentRequest" : { "HomeCommunityId" : "urn:oid:2.16.840.1.113883.3.1970.1", "RepositoryUniqueId" : "2.16.840.1.113883.3.1970.1", "DocumentUniqueId" : "2.16.840.1.113883.3.1970.1^SOZyOX4vFREzOe4G" } } However, an XML payload like this, which differs by prefixing every element with a namespace:

urn:oid:2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.1^SOZyOX4vFREzOe4G ` Will produce JSON like this: ` { "@xmlnsprefix": "ns5", "@xmlns:ns5": "urn:ihe:iti:xds-b:2007", "DocumentRequest": { "@xmlnsprefix": "ns5", "HomeCommunityId": { "@xmlnsprefix": "ns5", "$": "2.16.840.1.113883.3.1970.1" }, "RepositoryUniqueId": { "@xmlnsprefix": "ns5", "$": "2.16.840.1.113883.3.1970.1" }, "DocumentUniqueId": { "@xmlnsprefix": "ns5", "$": "2.16.840.1.113883.3.1970.1^EnRatgPRGxhRk301" } } } ` This can be problematic since the channel will have to check for text content in either json.DocumentUniqueId or json.DocumentUniqueId.$. It would help to have an option to always add text content as a $ property. ---------- Another option that would be useful would be to always convert elements to arrays so that you don't have to check both element.value or element[0].value. For example, expanding on the earlier DocumentRequest XML, it's possible to have multiple requests like this: ` urn:oid:2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.1^SOZyOX4vFREzOe4G urn:oid:2.16.840.1.113883.3.1970.1 2.16.840.1.113883.3.1970.2 2.16.840.1.113883.3.1970.1^AOZyOX4vFREzOe4G ` This results in a JSON array like this as expected: ` [ { "HomeCommunityId" : "urn:oid:2.16.840.1.113883.3.1970.1", "RepositoryUniqueId" : "2.16.840.1.113883.3.1970.1", "DocumentUniqueId" : "2.16.840.1.113883.3.1970.1^SOZyOX4vFREzOe4G" }, { "HomeCommunityId" : "urn:oid:2.16.840.1.113883.3.1970.1", "RepositoryUniqueId" : "2.16.840.1.113883.3.1970.2", "DocumentUniqueId" : "2.16.840.1.113883.3.1970.1^AOZyOX4vFREzOe4G" } ] ` Compare this with the earlier JSON where the DocumentRequest element was an object. It would be nice to be able to loop through the list of document requests without first having to verify if it's an array. Imported Issue. Original Details: Jira Issue Key: MIRTH-4453 Reporter: narupley Created: 2019-09-17T08:48:57.000-0700
rbeckman-nextgen commented 5 years ago

Added new "expanded format" options to the interop connectors. When enabled, arrays are always used even if only one property of a give name exists, and text values are always contained within the "$" property of a sub-object.

Imported Comment. Original Details: Author: narupley Created: 2019-09-17T08:50:51.000-0700