Author |
Message
|
ghoshly |
Posted: Mon Nov 16, 2015 9:57 am Post subject: Validation of JSON message |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
Hello,
My current environment is WMB V8.0.0.6 with WMQ 7.5.0.5
In order to validate a JSON message I am converting the message into XML format with straight forward ESQL as
Code: |
SET OutputRoot.XMLNSC.Data = InputRoot.JSON.Data; |
I am getting some trouble with number data in the JSON message as during parsing, the representation is changed.
Quote: |
"Rate" : 3.5965,
"Price" : 19.90, |
is changed to
Quote: |
(0x03000000:NameValue):Rate = 3.5965E+0 (FLOAT)
(0x03000000:NameValue):Price = 1.99E+1 (FLOAT)
|
and causing XSD schema validation or when mapped to end system, their WSDL validation is also not successful. Could you please guide me how to resolve this? |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Nov 16, 2015 10:00 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
IIB doesn't currently support validation against things that count as JSON schemas.
Is there a strict business requirement to handle this validation inside IIB? _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ghoshly |
Posted: Mon Nov 16, 2015 10:37 am Post subject: Is it the JSON parser changing the representation? |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
I understand that the validation of JSON schema is not supported.
Here we are trying to validate a XML message against XML schema and we are deriving the XML message based on JSON message.
Is it the JSON parser who is changing the representation?
There is business requirement to validate the incoming (JSON) message because we are exposing service to third party and the organisation wants to validate the data before consuming it into internal systems.
Thanks for your help. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Nov 16, 2015 10:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Well, the XML schema probably says the number is a float. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
Vitor |
Posted: Mon Nov 16, 2015 10:53 am Post subject: Re: Is it the JSON parser changing the representation? |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ghoshly wrote: |
Is it the JSON parser who is changing the representation? |
Well the value isn't actually changing is it 19.90 is the same value as 1.99E+1 so the question come what sort of validation do you need to do? If it's range checking ("Price must be greater than zero and below x") then either representation will work just fine. Why does the representation matter?
I agree with my most worthy associate that if you want your XML the other way then defining Price as xs:decimal not xs:float might be a start. Are you mapping to the XSD referenced by the WSDL? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ghoshly |
Posted: Mon Nov 16, 2015 11:10 am Post subject: Number representation |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
Hello,
Even my idea was similar that the representation may vary but that should not cause any problem. We are not even doing range check at this point of time (though the plan is there, once the current setup works). Mentioned below is the snippet from the schema where it is defined as decimal.
Code: |
<xsd:element name="Price">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="22"/>
<xsd:fractionDigits value="3"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element> |
After receiving the JSON format message from external source we need to validate the message and call a internal SOAP web service to pass the required data in the right format. |
|
Back to top |
|
 |
Vitor |
Posted: Mon Nov 16, 2015 11:28 am Post subject: Re: Number representation |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ghoshly wrote: |
Mentioned below is the snippet from the schema where it is defined as decimal. |
Vitor wrote: |
Are you mapping to the XSD referenced by the WSDL? |
Specifically, how does the XMLNSC tree you refer to:
ghoshly wrote: |
Code: |
SET OutputRoot.XMLNSC.Data = InputRoot.JSON.Data; |
|
reference the XSD and the data types therein? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Nov 16, 2015 12:05 pm Post subject: Re: Number representation |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
Specifically, how does the XMLNSC tree you refer to:
ghoshly wrote: |
Code: |
SET OutputRoot.XMLNSC.Data = InputRoot.JSON.Data; |
|
reference the XSD and the data types therein? |
Is your top level item in the XSD really named "Data" ? _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ghoshly |
Posted: Mon Nov 16, 2015 12:54 pm Post subject: This is snippet data |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
Hello Jeff,
I have given snippet data to show how I am building the XML. In actual I have used create lastchild syntax
Even if I do not validate the message in ESB, in target side SOAP webservice returns SOAP fault as
Quote: |
<soapenv:fault>
<faultcode>Internal Server Error</faultcode>
<faultstring>The incoming message is invalid with the following errors: urn:Ariba:Buyer:vsap:SXNBORequisitionStaging</faultstring>
<detail>cvc-datatype-valid.1.2.1: '4E+1' is not a valid value for 'decimal'.</detail>
<detail>cvc-type.3.1.3: The value '4E+1' of element 'NS1:Quantity' is not valid.</detail>
<detail>cvc-datatype-valid.1.2.1: '1.48E+1' is not a valid value for 'decimal'.</detail>
<detail>cvc-type.3.1.3: The value '1.48E+1' of element 'NS1:Amount' is not valid.</detail>
<detail>cvc-datatype-valid.1.2.1: 'NaN' is not a valid value for 'decimal'.</detail>
<detail>cvc-type.3.1.3: The value 'NaN' of element 'NS1:Amount' is not valid.</detail>
</soapenv:fault> |
|
|
Back to top |
|
 |
mqjeff |
Posted: Mon Nov 16, 2015 1:06 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The XMLNSC parser matches the schema to the XML document based on the the name and namespace of the root element of the XML document - the first child of XMLNSC.
If your schema does not have a top level element named "Data", you will have to move your JSON data into something other than a top level element named "Data".
Maybe that's what you mean when you say you use the create last child syntax...
You might also have to do a more specific mapping from your JSON fields to your XML fields, in order to prevent these kinds of format errors by casting fields into the right types.
Or at least enable the content and value options on the node. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ghoshly |
Posted: Mon Nov 16, 2015 1:35 pm Post subject: |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
Hi Jeff,
The Root tag matches the schema definition. I mean this code -
Code: |
-- Declare references
DECLARE RF_InMsgRoot REFERENCE TO InputRoot.JSON.Data.*[<];
-- Create outputMessage Payload from Input Message
CREATE LASTCHILD OF RF_MessagePayload FROM RF_InMsgRoot; |
We have one to one field level mapping via XSLT to the target end system. If I wrap the decimal data into " " to make it a string when its reaching ESB and disable validation, it goes to the target end without problem.
Somehow the float representation is changing the content. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Nov 16, 2015 1:38 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Ok.
So you're assigning OutputRoot.XMLNSC.<something> to the name of the first child of the JSON document. Presumably this matches the name of the root tag of one of your XML messages.
Does your XSD specify a namespace for that message? I'd be shocked, and slightly horrified, if your JSON element were able to map the namespace as well as the name.
All of this really could be causing the float instead of decimal representation. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ghoshly |
Posted: Mon Nov 16, 2015 2:01 pm Post subject: |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
There is no name space in the XSD or the incoming JSON message |
|
Back to top |
|
 |
Vitor |
Posted: Mon Nov 16, 2015 2:10 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ghoshly wrote: |
There is no name space in the XSD |
A WSDL with no namespace?
That's like fish without chips; strictly speaking legal but very, very implausible. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mgk |
Posted: Mon Nov 16, 2015 2:25 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
<detail>cvc-datatype-valid.1.2.1: '4E+1' is not a valid value for 'decimal'.</detail> |
As pointed out above, this is the most likely reason for the failure - try changing the XSD to use xsd:float rather than xsd:decimal.
Kind regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
|