ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Validation of JSON message

Post new topic  Reply to topic Goto page 1, 2, 3  Next
 Validation of JSON message « View previous topic :: View next topic » 
Author Message
ghoshly
PostPosted: Mon Nov 16, 2015 9:57 am    Post subject: Validation of JSON message Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 325

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
View user's profile Send private message
mqjeff
PostPosted: Mon Nov 16, 2015 10:00 am    Post subject: Reply with quote

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
View user's profile Send private message
ghoshly
PostPosted: Mon Nov 16, 2015 10:37 am    Post subject: Is it the JSON parser changing the representation? Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 325

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
View user's profile Send private message
mqjeff
PostPosted: Mon Nov 16, 2015 10:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Mon Nov 16, 2015 10:53 am    Post subject: Re: Is it the JSON parser changing the representation? Reply with quote

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
View user's profile Send private message
ghoshly
PostPosted: Mon Nov 16, 2015 11:10 am    Post subject: Number representation Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 325

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
View user's profile Send private message
Vitor
PostPosted: Mon Nov 16, 2015 11:28 am    Post subject: Re: Number representation Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Mon Nov 16, 2015 12:05 pm    Post subject: Re: Number representation Reply with quote

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
View user's profile Send private message
ghoshly
PostPosted: Mon Nov 16, 2015 12:54 pm    Post subject: This is snippet data Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 325

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: &apos;4E+1&apos; is not a valid value for &apos;decimal&apos;.</detail>
<detail>cvc-type.3.1.3: The value &apos;4E+1&apos; of element &apos;NS1:Quantity&apos; is not valid.</detail>
<detail>cvc-datatype-valid.1.2.1: &apos;1.48E+1&apos; is not a valid value for &apos;decimal&apos;.</detail>
<detail>cvc-type.3.1.3: The value &apos;1.48E+1&apos; of element &apos;NS1:Amount&apos; is not valid.</detail>
<detail>cvc-datatype-valid.1.2.1: &apos;NaN&apos; is not a valid value for &apos;decimal&apos;.</detail>
<detail>cvc-type.3.1.3: The value &apos;NaN&apos; of element &apos;NS1:Amount&apos; is not valid.</detail>
</soapenv:fault>
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Nov 16, 2015 1:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
ghoshly
PostPosted: Mon Nov 16, 2015 1:35 pm    Post subject: Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 325

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
View user's profile Send private message
mqjeff
PostPosted: Mon Nov 16, 2015 1:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
ghoshly
PostPosted: Mon Nov 16, 2015 2:01 pm    Post subject: Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 325

There is no name space in the XSD or the incoming JSON message
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Nov 16, 2015 2:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
mgk
PostPosted: Mon Nov 16, 2015 2:25 pm    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1638

Quote:
<detail>cvc-datatype-valid.1.2.1: &apos;4E+1&apos; is not a valid value for &apos;decimal&apos;.</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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2, 3  Next Page 1 of 3

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Validation of JSON message
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.