Package org.codehaus.groovy.grails.web.json

Examples of org.codehaus.groovy.grails.web.json.JSONWriter.object()


    public void marshalObject(Object object, JSON json) throws ConverterException {
        Errors errors = (Errors) object;
        JSONWriter writer = json.getWriter();

        try {
            writer.object();
            writer.key("errors");
            writer.array();

            for (Object o : errors.getAllErrors()) {
                if (o instanceof FieldError) {
View Full Code Here


            writer.array();

            for (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) {
View Full Code Here

                        json.property("message", fe.getDefaultMessage());
                    }
                    writer.endObject();
                } else if (o instanceof ObjectError) {
                    ObjectError fe = (ObjectError) o;
                    writer.object();
                    json.property("object", fe.getObjectName());
                    Locale locale = LocaleContextHolder.getLocale();
                    if (applicationContext != null) {
                        json.property("message", applicationContext.getMessage(fe, locale));
                    }
View Full Code Here

        GrailsDomainClass domainClass = (GrailsDomainClass)application.getArtefact(
              DomainClassArtefactHandler.TYPE, ConverterUtil.trimProxySuffix(clazz.getName()));
        BeanWrapper beanWrapper = new BeanWrapperImpl(value);

        writer.object();

        if(shouldInclude(includeExcludeSupport, includes, excludes, value, "class")) {
            writer.key("class").value(domainClass.getClazz().getName());
        }
View Full Code Here

                            else if (referenceObject instanceof Map) {
                                Map<Object, Object> map = (Map<Object, Object>) referenceObject;
                                for (Map.Entry<Object, Object> entry : map.entrySet()) {
                                    String key = String.valueOf(entry.getKey());
                                    Object o = entry.getValue();
                                    writer.object();
                                    writer.key(key);
                                    asShortObject(o, json, referencedIdProperty, referencedDomainClass);
                                    writer.endObject();
                                }
                            }
View Full Code Here

        }
        else {
            idValue = extractValue(refObj, idProperty);
        }
        JSONWriter writer = json.getWriter();
        writer.object();
        writer.key("class").value(referencedDomainClass.getFullName());
        writer.key("id").value(idValue);
        writer.endObject();
    }
View Full Code Here

        return object instanceof Map;
    }

    public void marshalObject(Object o, JSON converter) throws ConverterException {
        JSONWriter writer = converter.getWriter();
        writer.object();
        Map<Object,Object> map = (Map<Object,Object>) o;
        for (Map.Entry<Object,Object> entry : map.entrySet()) {
            Object key = entry.getKey();
            if (key != null) {
                writer.key(key.toString());
View Full Code Here

        Class<? extends Object> clazz = o.getClass();
        List<String> excludes = json.getExcludes(clazz);
        List<String> includes = json.getIncludes(clazz);
        IncludeExcludeSupport<String> includeExcludeSupport = new IncludeExcludeSupport<String>();
        try {
            writer.object();
            for (PropertyDescriptor property : BeanUtils.getPropertyDescriptors(clazz)) {

                Method readMethod = property.getReadMethod();
                String name = property.getName();
View Full Code Here

    }

    public void marshalObject(Object en, JSON json) throws ConverterException {
        JSONWriter writer = json.getWriter();
        try {
            writer.object();
            Class<?> enumClass = en.getClass();
            json.property("enumType", enumClass.getName());
            Method nameMethod = BeanUtils.findDeclaredMethod(enumClass, "name", null);
            try {
                json.property("name",nameMethod.invoke(en));
View Full Code Here

    }

    public void marshalObject(Object o, JSON json) throws ConverterException {
        JSONWriter writer = json.getWriter();
        try {
            writer.object();
            for (PropertyDescriptor property : BeanUtils.getPropertyDescriptors(o.getClass())) {
                String name = property.getName();
                Method readMethod = property.getReadMethod();
                if (readMethod != null) {
                    Object value = readMethod.invoke(o, (Object[]) null);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.