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

E4X XML objects throw errors when stringifying them via JSON #3679

Closed
rbeckman-nextgen opened this issue May 11, 2020 · 3 comments
Closed

E4X XML objects throw errors when stringifying them via JSON #3679

rbeckman-nextgen opened this issue May 11, 2020 · 3 comments
Milestone

Comments

@rbeckman-nextgen
Copy link
Collaborator

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

This was technically always a problem, but it has manifested itself much more clearly now in 3.3 with the new JSON data type. Basically when you call JSON.stringify and pass in an E4X XML object (or an object that contains one), it fails because toJSON isn't implemented. We should at least make it so that stringify works, even if the JSON representation for an XML node is just a string.

Imported Issue. Original Details:
Jira Issue Key: MIRTH-3796
Reporter: narupley
Created: 2015-09-21T14:38:52.000-0700

@rbeckman-nextgen rbeckman-nextgen added this to the 3.3.1 milestone May 11, 2020
@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

Revisions 7825/7826: E4X XML and XMLList objects now implement toJSON. It acts exactly like toString does for now, nothing fancy.

Imported Comment. Original Details:
Author: narupley
Created: 2015-09-24T16:17:16.000-0700

@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

Server(s) and URLs Used: Run Mirth Connect on local OSX Yosemite 10.10
Version(s)/Build(s) to reproduce failure: mirthconnect-3.3.0.7801.b1804-unix
Version(s)/Build(s) to verify fixes: mirthconnect-3.3.0.7829.b1816-unix
How Tested (list tests run):

  • Run Mirth Connect
  • Create new channel using default Source/Target = Channel Reader/Writer
  • Channel Summary > Set Data Type > Inbound = HL7, Outbound = JSON
  • Create Destination Transformer Type = JavaScript
    var object = {}; object.firstName = msg['PID']['PID.5']['PID.5.2'].toString(); object.lastName = msg['PID']['PID.5']['PID.5.1'].toString(); msg = JSON.stringify(object);
  • Save and Deploy channel
  • Send HL7 msg to channel and verify msg sent successfully
  • Now modify JavaScript to remove “toString()” from each object line
  • Save and Re-deploy channel
  • Send the same HL7 msg and verify result

Verified Fixed:
Revision #7829, msgs received and sent without error in both scenario.
In previous build, Revision #7801, message failed to transform when remove the “.toString()” presentation
Transformer error ERROR MESSAGE: Error evaluating transformer com.mirth.connect.server.MirthJavascriptTransformerException: CHANNEL: mirth3796_JSON and E4X object CONNECTOR: Destination 1 SCRIPT SOURCE: TRANSFORMER SOURCE CODE: 144: 145: 146: var object = {}; 147: object.firstName = msg['PID']['PID.5']['PID.5.2']; 148: object.lastName = msg['PID']['PID.5']['PID.5.1']; 149: msg = JSON.stringify(object); 150: if ('xml' === typeof msg && msg.hasSimpleContent()) { msg = msg.toXMLString(); }if ('xml' === typeof tmp && tmp.hasSimpleContent()) { tmp = tmp.toXMLString(); } 151: } 152: if (doFilter() == true) { doTransform(); return true; } else { return false; } 153: } LINE NUMBER: 149 DETAILS: TypeError: Cannot find function toJSON in object COLLEEN. at b02d4a16-5066-4816-952f-7cda528e7599:149 (doTransform) at b02d4a16-5066-4816-952f-7cda528e7599:152 (doScript) at b02d4a16-5066-4816-952f-7cda528e7599:154 at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.call(JavaScriptFilterTransformer.java:154) at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.call(JavaScriptFilterTransformer.java:119) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

Imported Comment. Original Details:
Author: minht
Created: 2015-10-06T11:19:42.000-0700

@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

Verified E4X XML objects implemented toJSON with mirthconnect-3.3.0.7829.b1816-unix

Imported Comment. Original Details:
Author: minht
Created: 2015-10-06T11:22:33.000-0700

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.