It's a brute force method where you strip you line down to the simplest it can be so you can see what it does and then build up the pieces again.
Start by commenting everything out except for a line like this:
returnMap.put("Total",inputMap.get("Value1"));
Verify what the value looks like.
Then start adding things in like:
returnMap.put("Total",(int)inputMap.get("Value1"));
And we get the error even on something that simple
. Now I start googling groovy cast string to int. I find several suggested ways of doing it:
int intNum = stringNum as int
or
int intNum = stringNum.toInteger()
or
int intNum = new Integer(stringNum).intValue()
or
int intNum = Integer.valueOf(stringNum)
or
def intVal = stringVal1 as Integer
Okay - I'm going to pick the first because it seems simplest and try (with no quotes inside the input value):
int numVal1 = inputMap.get("Value1") as int;
returnMap.put("Total",numVal1);
Which works. That's what I mean by breaking it down and brute forcing it.
This intrigued me, so I fiddled around some more. I tried:
int numVal2 = (Integer)inputMap.get("Value2");
which did not give you the error trying to cast, but it didn't return the correct result. (53 instead of 5
)
I tried this:
def numVal2 = inputMap.get("Value2") as Integer;
and it did return the correct value
As you can guess, I'm not a java/groovy developer either. So I spend a lot of time working my way through the simple stuff figuring out what works.