Querying database in Grails -
the values in database saved such ::{"rating1":"2","rating2":"4","rating3":"5","rating4":"0","rating5":"0"}, need acces individual values 2,4,5 etc.
i made variable "rating" of domain class type , tried accesing object using (.) operator wont work , gives error: :exception::groovy.lang.missingpropertyexception: no such property: rating1 class: java.lang.string
, tried casting array , list (as array, arraylist, list) etc wont work either. casting list gives exception:exception::org.codehaus.groovy.runtime.typehandling.groovycastexception: cannot cast object '{"rating1":"2","rating2":"4","rating3":"5","rating4":"0","rating5":"0"}' class 'java.lang.string' class 'java.util.list' .
accessing "rating[3]" gives answer "a". should use "rating[11]" value 2 or there way around. possible solution. please help.
you're storing string, have string operations available. need parse string @ attributes individually (jsonslurper perhaps?).
rating[character-position] bad idea imo.
maybe transients (check gorm docs) useful.
class yourdomain { string yourfield string getrating1() { new jsonslurper().parsetext(yourfield).rating1 } }
maybe. totally untested, idea.
Comments
Post a Comment