marshalling - Grails JSON marshaller for FieldErrors -


i'm trying create custom marshaller org.springframework.validation.fielderror can avoid putting extraneous , possibly sensitive data in json response, includes mycommandobject.errors.

however fielderror marshaller isn't working @ all, have in bootstrap.groovy under init method.

    def fielderrormarshaller = {         log.info("field error marshaller $it")         def returnarray = [:]          returnarray['field'] = it.field         returnarray['message'] = it.message          return returnarray     }      json.registerobjectmarshaller(fielderror, fielderrormarshaller) 

i not seeing explicit errors or marshaller logging. idea might going wrong here?

grails register instance of validationerrorsmarshaller handle errors, fielderror marshaller never called.

//convertanother not called each error. that's reason of custom marshalled not been called. (object o : errors.getallerrors()) {     if (o instanceof fielderror) {         fielderror fe = (fielderror) o;         writer.object();         json.property("object", fe.getobjectname());         json.property("field", fe.getfield());         json.property("rejected-value", fe.getrejectedvalue());         locale locale = localecontextholder.getlocale();         if (applicationcontext != null) {             json.property("message", applicationcontext.getmessage(fe, locale));         }         else {         ... 

looking @ convertersgrailsplugin (descriptor of plugin) registered spring bean, can create bean , register same name, overriding marshalobject() fit needs (not tested, may need more code).

class myerrorsmarshaller implements objectmarshaller<json>, applicationcontextaware {     applicationcontext applicationcontext;      public boolean supports(object object) {         return object instanceof errors;     }      public void marshalobject(object object, json json) throws converterexception {     ...     }  } 

resources.groovy

jsonerrorsmarshaller(myerrorsmarshaller)  errorsjsonmarshallerregisterer(objectmarshallerregisterer) {     marshaller = { myerrorsmarshaller om -> }     converterclass = grails.converters.json } 

reference validationerrorsmarshaller.

reference convertersgrailsplugin.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -