Derek
Derek

Reputation: 11915

Get mapped value from Key in groovy

I have a map that I have printed, and I can see the values in it plain as day:

searchMatch.each {
    println("The match: " + it.employee.employeeID)
    int empID = Integer.parseInt(it.employee.employeeID);
    println("empID:" + empID)
    println("parsedResults: " + parsedResults)
    println("parsedResults[empID]: " + parsedResults[empID])
}

And the output is something like:

The match: 0518
empID:518
parsedResults: [518:[id:518, emp_name:Derek, title:Software Engineer ]]
parsedResults[empID]: null

So what's going on here? I am guessing I am using some wrong type for the key, but I just dont know how this is supposed to work in groovy really. If someone can explain whats going wrong here I'd appreciate it

Upvotes: 1

Views: 325

Answers (1)

Derek
Derek

Reputation: 11915

So as it turns out, the returned type for an "int" from a sql.rows() is a BigDecimal for the key. This is what was causing my comparisons to always come back false. I converted my string type of employee ID to a BigDecimal and it worked.

Upvotes: 1

Related Questions