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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -