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 » JSON double to XML decimal conversion

Post new topic  Reply to topic
 JSON double to XML decimal conversion « View previous topic :: View next topic » 
Author Message
vromac
PostPosted: Thu Mar 28, 2019 3:06 am    Post subject: JSON double to XML decimal conversion Reply with quote

Newbie

Joined: 21 Mar 2018
Posts: 7

Hello everyone, I have a very simple/stupid question, but can't find the proper knowledge resource to resolve it.

The context:
- using IIB v10.0.0.15
- I have a incoming JSON message that is a response from a REST service
- I want to map it to an outgoing XML message
- I am using the mapping node element
- one field on the input side is a json double type
- the destination element is a XML decimal type

The problem:
- I am using the convert transformation in the mapping node
- the source field can be NULL
[e.g, usertrace value for that field
(0x03000000:NameValue):myElement = NULL]

If I leave the convert as is, it works correctly for numeric values, however, if a NULL values comes [which is legitimate], the mapping fails with:

(0x03000000:NameValue):Text = 'Convert: element out18:myElement{ xs:decimal( xs:string( $parentElement/myElement) )}' (CHARACTER)
(0x03000000:NameValue):Text = 'IXJXE0458E: [ERR 0407][ERR FORG0001] The operand cannot be cast to type 'xs:decimal?'.' (CHARACTER)

The idea is to use the condition tab to filter NULL elements and not to convert at all. However, whichever solution I tried, it either gets false positives or false negatives

Some solutions I've used:
$myElement != null
$myElement != ''
fn:empty($myElement) = false
fn:exists($myElement) = false
fn:nillable($myElement) = false
fn:string-length($myElement) > 0
fn:boolean($myElement/text()) = fn:true()
fn:exists($myElement) and (fn:nilled( $myElement) = false)


Alternative solution - use the custom ESQL transformation, but what would be the functions signature and implementation then?

CREATE FUNCTION convertDoubleToDecimal(IN decimalAmount ???) RETURNS DECIMAL


Last edited by vromac on Mon Apr 01, 2019 6:13 am; edited 1 time in total
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Mar 28, 2019 5:09 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Is the null value allowed for the target field? (xsd:nillable="true")?
If it is not, what value would you attribute a null value to (0)?

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
vromac
PostPosted: Thu Mar 28, 2019 7:44 am    Post subject: Reply with quote

Newbie

Joined: 21 Mar 2018
Posts: 7

It doesn't have the nullable=true attribute, no, but is marked optional [i.e. minOccurs=0].

So the result should be to skip the mapping and not create the destination element at all.


By the way, the solution I've been chasing now is to use custom esql with the following code

Code:

CREATE FUNCTION convertDoubleToDecimal(IN decimalAmount FLOAT) RETURNS DECIMAL
BEGIN      
   DECLARE temp DECIMAL;
   IF decimalAmount is not NaN Then
      SET temp = CAST(decimalAmount AS DECIMAL(12,2));
   else
      SET temp = null;
   END IF;
   RETURN temp;
END;


Still testing for edge cases...
Back to top
View user's profile Send private message
timber
PostPosted: Fri Mar 29, 2019 2:16 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

Quote:
is marked optional [i.e. minOccurs=0].
So the result should be to skip the mapping and not create the destination element at all.
I think there is some confusion going on here. A null value is a value for an existing element. So minOccurs is not relevant (minOccurs is about whether an element exists at all).

The ESQL function is probably the best solution.
Back to top
View user's profile Send private message
vromac
PostPosted: Fri Mar 29, 2019 6:30 am    Post subject: Reply with quote

Newbie

Joined: 21 Mar 2018
Posts: 7

Yeah, I've figured it as a question what do I want for the destination field to look like after the call

if nillable it could look like

Quote:
...
<someElement>blabla</someElement>
<myElement/>
<someOtherElement>blabla</someOtherElement>
...


but, as I have it as minOccurs, I'd want it as

Code:

...
<someElement>blabla</someElement>
<someOtherElement>blabla</someOtherElement>
...


so yeah, the ESQL was the way I went, works as I want it for null and non-null values.
Back to top
View user's profile Send private message
timber
PostPosted: Fri Mar 29, 2019 7:02 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

No, I'm afraid you have a wrong understanding of what 'nillable' means. The term 'nillable' has a very precise meaning in an XML document. See the XML specification, or a good XML tutorial.
Back to top
View user's profile Send private message
vromac
PostPosted: Mon Apr 01, 2019 5:20 am    Post subject: Reply with quote

Newbie

Joined: 21 Mar 2018
Posts: 7

timber wrote:
No, I'm afraid you have a wrong understanding of what 'nillable' means. The term 'nillable' has a very precise meaning in an XML document. See the XML specification, or a good XML tutorial.


You are right. So if the nillable attribute is used I'd get a response like
Code:

...
<someElement>blabla</someElement>
<myElement xsi:nil='true'/>
<someOtherElement>blabla</someOtherElement>
...


which depends on the service consumer to know how to work with it. But still, my goal was to skip the transformation and not create the destination element at all.

Seeing the final ESQL solution works, I'm content to use it and abandon the convert+conditional path.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JSON double to XML decimal conversion
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.