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 » manipulate JSON message in Java compute node

Post new topic  Reply to topic
 manipulate JSON message in Java compute node « View previous topic :: View next topic » 
Author Message
wmqstankela
PostPosted: Wed Mar 14, 2018 4:43 am    Post subject: manipulate JSON message in Java compute node Reply with quote

Voyager

Joined: 29 Feb 2016
Posts: 94

Hi all,

I need some help. I have REST service and my input is JSON with array of attributes:
Code:

(0x01000000:Object):JSON            = ( ['json' : 0x23f317914f0]
    (0x01000000:Object):Data = (
      (0x01001000:Array    ):attributes = (
        (0x01000000:Object):Item = (
          (0x01000000:Object):attribute = (
            (0x03000000:NameValue):name  = 'name' (CHARACTER)
            (0x03000000:NameValue):value = 'John' (CHARACTER)
          )
        )
        (0x01000000:Object):Item = (
          (0x01000000:Object):attribute = (
            (0x03000000:NameValue):name  = 'lastname' (CHARACTER)
            (0x03000000:NameValue):value = 'Doe' (CHARACTER)
          )
        )
        (0x01000000:Object):Item = (
          (0x01000000:Object):attribute = (
            (0x03000000:NameValue):name  = 'mail' (CHARACTER)
            (0x03000000:NameValue):value = 'john.doe@example.com' (CHARACTER)
          )
        )
      )
    )


Number of attributes is dynamic parameter, and I don't know how many attributes client will send to service. How to iterate through input JSON message in Java compute node and populate attributes in list of attribute?

Thanks in advance!
Back to top
View user's profile Send private message
timber
PostPosted: Wed Mar 14, 2018 12:33 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

Don't want to sound unhelpful but...what have you tried? There are quite a few answers, and it's hard to know where to start. And the 'correct' answer may depend on requirements that you haven't mentioned yet.
Back to top
View user's profile Send private message
wmqstankela
PostPosted: Thu Mar 15, 2018 5:17 am    Post subject: Reply with quote

Voyager

Joined: 29 Feb 2016
Posts: 94

I've done it, thanks timber anyway.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Mar 15, 2018 5:43 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

wmqstankela wrote:
I've done it, thanks timber anyway.


Care to post your solution for the benefit of future readers?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
wmqstankela
PostPosted: Thu Mar 15, 2018 6:10 am    Post subject: Reply with quote

Voyager

Joined: 29 Feb 2016
Posts: 94

I've put JSON message in MbElement and then iterate through that element using while loop and getNextSibling() method, until I reached getLastChild element.
First need to manipulate with first attribute, and then iterate through the rest of them. Something like that:
Code:

List<Attribute> attributes = new ArrayList<Attribute>();
MbElement paramAttributes = inJsonRoot.getFirstElementByPath("/JSON/Data/attributes");
MbElement firstItem = paramAttributes.getFirstChild();
MbElement lastItem = paramAttributes.getLastChild();
boolean isLast= false;
while !(isLast){
  firstItem = firstItem.getNextSibling();
  if (firstItem.is(lastItem)){ isLast= true; }
a = new Attribute(firstItem.getFirstChild().getFirstChild().getValueAsString(), firstItem.getFirstChild().getLastChild().getValueAsString());
             attributes.add(a);                          
         }
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 » manipulate JSON message in Java compute node
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.