KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to register a custom json marshaller like this JSON.createNamedConfig("dynamic",{ def m = new CustomJSONSerializer() JSON.registerObjectMarshaller(Idf, 1, { instance, converter -> m.marshalObject(instance, converter) }) }) and then using it like this JSON.use("dynamic"){ render inventionList as JSON } but I am not sure if my custom serializer is being used because when I am debugging control never goes to marshalObject function of my custom serializer My custom serializer is as follows import grails.converters.deep.JSON import java.beans.PropertyDescriptor import java.lang.reflect.Field import java.lang.reflect.Method import org.codehaus.groovy.grails.web.converters.exceptions.ConverterException import org.codehaus.groovy.grails.web.converters.marshaller.json.GroovyBeanMarshaller import org.codehaus.groovy.grails.web.json.JSONWriter class CustomJSONSerializer extends GroovyBeanMarshaller{ public boolean supports(Object object) { return object instanceof GroovyObject; } public void marshalObject(Object o, JSON json) throws ConverterException { JSONWriter writer = json.getWriter(); println 'properties '+BeanUtils.getPropertyDescriptors(o.getClass()) for(PropertyDescriptor property:BeanUtils.getProperyDescriptors(o.getClass())){ println 'property '+property.getName() } try { writer.object(); for (PropertyDescriptor property : BeanUtils.getPropertyDescriptors(o.getClass())) { String name = property.getName(); Method readMethod = property.getReadMethod(); if (readMethod != null && !(name.equals("metaClass")) && readMethod.getName()!='getSpringSecurityService') { Object value = readMethod.invoke(o, (Object[]) null);
Tags (comma-separated)
Save Edits
Cancel