• It processes the json data coming from the client by looping through the data. In this example, it is assumed that the incoming data contains a list of employee information.


def parser = new groovy.json.JsonSlurper()
def jsonData = parser.parseText(requestBodyTextFromClient)

static String someRandomMethod(String input, int inputNumber) {
	//Processes..
    return input
}

for(Object data in jsonData.data) {
  data.name = someRandomMethod(data.name, 1)
  data.surname = someRandomMethod(data.surname, 3)
  data.phoneNumber = someRandomMethod(data.phoneNumber, 5)
}


GROOVY
  • It copies the json data coming from the client to the header region of the message and sends it to the back side. If there are child objects or lists, it adds them as they are.


def parser = new groovy.json.JsonSlurper()
def jsonData = parser.parseText(requestBodyTextFromClient)

jsonData.each { k, v ->    
      requestHeaderMapToTargetAPI.put(k,v)
}
GROOVY
  • It takes the json data coming from the client with the sequence information of each value and uses it in the loop.


def parser = new groovy.json.JsonSlurper();
def jsonData = parser.parseText(requestBodyTextFromClient);

static String someRandomMethod(String input, int inputNumber) {
	//Processes..
    return input
}

jsonData.eachWithIndex { val, idx -> 
   val = someRandomMethod(val, idx)
}
GROOVY