groovy - Set grails domain object property without calling the setter method -


domain person has property name. setter method has been overridden store name embedded inside internationalization object within person object as:

internationalization: {     name: {        en: engilshname,        fr: frenchname     } } 

therefore piece of code:

def person = new person() person.setname('merhawi', new locale('en')) person.setname('frenchmerhawi', new locale('fr')) person.save() 

would store name inside mongo database as:

{     _id: numberlong(1),     internationalization: {         name: {            en: "merhawi",            fr: "frenchmerhawi"         }     } } 

invoking getname on person return correct name depending on current locale of environment.

now trying is: person json data want field name contains correct name depending on current locale of environment besides other fields. trying set person.name = person.getname() before returning person grails.converters.json call setter method , doesn't give name field. instead tries store name in same embedded manner.

how add name field without calling setter method?

person.metaclass.setname = {-> delegate.name = delegate.getname()} person.setname(); return [person] grails.converters.json 

solved problem.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -