Search code examples
grailsgroovy

Grails. Incorrect values are assigned in variables from params


When I try assigned value from params it now works incorrect.

System.out.println(params.test)   // I see 0
int test = params.test
System.out.println(test)   // I see 48

some my integer and float variables assigned value + 48

some boolean valiable all assigned true

I tried change grails version (2.3.7/2.3.4), rebuild project. But it works wrong. May be I changed some settings?


Solution

  • Nothing is wrong here.

    params.test has string value 0

    params.test = "0"
    

    when it is type casted to int it's ascii value 48 gets assigned to test

    assert 48 == (int)"0"
    

    To get int value of string "0" from params you can use primitive methods applicable on params

    params.int('test') // int 0
    

    similarly for boolean

    params.boolean('test') //boolean true/false