Home › Forums › Integration › Messages › Are we doing something wrong here?
Tagged: JSON format-message
- This topic has 8 replies, 2 voices, and was last updated 8 years, 4 months ago by Owen Pond.
-
AuthorPosts
-
-
July 6, 2016 at 1:54 pm #6928Rob DudaParticipant
We have come across something with format-message that we believe is a bug but wanted to ensure that we are not doing something that the framework considers incorrect. The problem occurs when a JSON format message contains a nested collection of messages. The format-message function will throw a class cast exception any time this structure exists.
12345678910111213141516171819202122232425262728293031323334(format-message(message(: :class "JsonError")(: topObject(collection(message(: innerObject(collection(message (: value "inner")))))(: value "top")))));Error: Error formatting the message "JsonError".at nexj.core.integration.format.json.JSONMessageFormatter.format(JSONMessageFormatter.java:92)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at nexj.core.scripting.JavaMethod.invoke(JavaMethod.java:226)at integration.lambda(library:integration:63)Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to nexj.core.rpc.TransferObjectat nexj.core.integration.format.json.JSONMessageFormatter.formatCompositeMessagePart(JSONMessageFormatter.java:200)at nexj.core.integration.format.json.JSONMessageFormatter.formatCompositeMessagePart(JSONMessageFormatter.java:219)at nexj.core.integration.format.json.JSONMessageFormatter.format(JSONMessageFormatter.java:84)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)0Attachments:
You must be logged in to view attached files. -
July 6, 2016 at 2:03 pm #6936Owen PondParticipant
Just taking a quick look; it looks like you’re adding
1(: value "top")to the “topObject” collection, without it being part of a message definition.
Let us know if that was the problem.
0 -
July 6, 2016 at 2:09 pm #6944Rob DudaParticipant
No, value is part of topObject. I attached the message definition below. I also added the capture of the hints at that part of the code. I don’t know why my formatting above had the white-space stripped out, makes it hard to read.
0Attachments:
You must be logged in to view attached files. -
July 6, 2016 at 2:30 pm #6953Owen PondParticipant
When I format the code I still see this…
1234567891011121314(format-message(message(: :class "JsonError")(: topObject(collection(message(: innerObject (collection (message (: value "inner")))))(: value "top")))))))And if I just execute the 1st level (message) function the output is this
1234567891011#<TO<JsonError, @1154853637>(topObject={TO<, @667875473>(innerObject={TO<, @86051842>(value="inner")}),(value . "top")})>Which has a pair in the middle of the resulting transfer object. Is that what you are expecting?
I’ve attached a screen shot of the formatted code.
0Attachments:
You must be logged in to view attached files. -
July 6, 2016 at 5:17 pm #6963Rob DudaParticipant
The message is intended to reproduce the actual problem we have experienced and was just thrown together so I could post the question. The JSON should look like so:
1{"topObject":[{"value":"top"},{"innerObject":[{"value":"inner"}]}]}If I just tried parse-message on the above JSON and it indeed parses into a TO:
1(parse-message "{\"topObject\":[{\"value\":\"top\"},{\"innerObject\":[{\"value\":\"inner\"}]}]}" "JsonError")1234567891011121314; #<TO<JsonError, @16867522>(topObject={TO<JsonError, @24611091>(value="top"),TO<JsonError, @13136233>(innerObject={TO<JsonError, @26067884>(value="inner")})})>So why does the framework throw the exception if I try to use format-message?
0 -
July 6, 2016 at 5:28 pm #6971
-
July 6, 2016 at 6:03 pm #6987Owen PondParticipant
I was able to produce your expected JSON result using the following message definition
1234567891011121314<Message format="JSON"><Parts><Message maxCount="0" name="topObject"><Parts><Value name="value" type="string"/><Message maxCount="0" name="innerObject"><Parts><Value name="value" type="string"/></Parts></Message></Parts></Message></Parts></Message>And consuming it with the following
12345678(format-message(message(: :class "JsonError")(: topObject(collection (message (: value "top") (: innerObject (collection (message (: value "inner")))))))))I’ll follow up a bit later with more explanation if this code works for you.
0 -
July 7, 2016 at 8:59 am #7009Rob DudaParticipant
I do not get the same result using your code above. Perhaps the problem is fixed in your version of the product. If that’s the case I’ll have someone work with support to see if there is a hotfix we can get before our next release. November-ish timeframe.
0Attachments:
You must be logged in to view attached files. -
July 7, 2016 at 9:35 am #7019Owen PondParticipant
It turns out that is the case. There was a fix made that would handle this case and is currently included in 7.2
Support will be able to help you request a hotfix.
1
-
-
AuthorPosts
- You must be logged in to reply to this topic.