App Connect

App Connect

Join this online user group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Array value traversion/manipulation in Java Compute Node

    Posted Mon April 03, 2023 07:56 AM

    Good Day,

    I currently have a task, it is to traverse and/or manipulate an array or array value using a Java compute node. I have seen documentation regarding this, here is the link: Modifying a JSON message

    Ibm remove preview
    Modifying a JSON message
    You can modify JSON objects and JSON arrays.
    View this on Ibm >

    The goal is like this (convert the index 1 to ABC)
    and here is what I did (based on docs):

    but it only ends with this error when we try to run it, 

    BIP4395E: Java exception: ''java.lang.NullPointerException''; thrown from class name: ''GetProfile_sample'', method name: ''evaluate'', file: ''GetProfile_sample.java'', line: '25'
    I don't know if I'm missing something or the documentation just really doesn't work


    ------------------------------
    Nathaniel Santiago
    ------------------------------


  • 2.  RE: Array value traversion/manipulation in Java Compute Node

    Posted Mon April 03, 2023 02:18 PM
    Edited by Gabriel Marte Blanco Mon April 03, 2023 04:16 PM

    Hi Nathaniel, 

    Here is a message from the team: 

    The XPath in incorrect. You are calling getFirstElementByPath. The correct path is "sampleArray/Item". Item[1] is an array index, not a path to an element name. The function getFirstElementByPath will always return the first instance of an array structure.  Try changing to Item and see if that works.

    Thank you,
    ------------------------------
    Gabriel Marte Blanco
    Austin TX
    ------------------------------



  • 3.  RE: Array value traversion/manipulation in Java Compute Node

    Posted Mon April 03, 2023 10:05 PM

    Hi @Gabriel Marte Blanco ,

    Thank you for your response. Yep, we tried that and it does work but we also need to target the direct path. We are traversing different JSON structures with deep arrays and objects and sometimes with a combination of both so we need to target the path directly without using the getChild or getSiblings. Are there any other ways to do it like the one in this documentation?

    Thank you,

    Regards, 

    Nathaniel



    ------------------------------
    Nathaniel Santiago
    ------------------------------