Search in sources :

Example 1 with ObjectMarshaller

use of org.grails.web.converters.marshaller.ObjectMarshaller in project grails-core by grails.

the class ConvertersConfigurationInitializer method initJSONConfiguration.

private void initJSONConfiguration() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Initializing default JSON Converters Configuration...");
    }
    List<ObjectMarshaller<JSON>> marshallers = new ArrayList<ObjectMarshaller<JSON>>();
    marshallers.addAll(getPreviouslyConfiguredMarshallers(JSON.class));
    marshallers.add(new org.grails.web.converters.marshaller.json.ArrayMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.json.ByteArrayMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.json.CollectionMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.json.MapMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.json.EnumMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.ProxyUnwrappingMarshaller<JSON>());
    Config grailsConfig = getGrailsConfig();
    if ("javascript".equals(grailsConfig.getProperty(SETTING_CONVERTERS_JSON_DATE, String.class, "default", Arrays.asList("javascript", "default")))) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Using Javascript JSON Date Marshaller.");
        }
        marshallers.add(new org.grails.web.converters.marshaller.json.JavascriptDateMarshaller());
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Using default JSON Date Marshaller");
        }
        marshallers.add(new org.grails.web.converters.marshaller.json.DateMarshaller());
    }
    marshallers.add(new org.grails.web.converters.marshaller.json.ToStringBeanMarshaller());
    boolean includeDomainVersion = includeDomainVersionProperty(grailsConfig, "json");
    boolean includeDomainClassName = includeDomainClassProperty(grailsConfig, "json");
    ProxyHandler proxyHandler = getProxyHandler();
    if (grailsConfig.getProperty(SETTING_CONVERTERS_JSON_DEFAULT_DEEP, Boolean.class, false)) {
        LOG.debug("Using DeepDomainClassMarshaller as default.");
        marshallers.add(new org.grails.web.converters.marshaller.json.DeepDomainClassMarshaller(includeDomainVersion, includeDomainClassName, proxyHandler, grailsApplication));
    } else {
        marshallers.add(new org.grails.web.converters.marshaller.json.DomainClassMarshaller(includeDomainVersion, includeDomainClassName, proxyHandler, grailsApplication));
    }
    marshallers.add(new org.grails.web.converters.marshaller.json.GroovyBeanMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller());
    DefaultConverterConfiguration<JSON> cfg = new DefaultConverterConfiguration<JSON>(marshallers, proxyHandler);
    cfg.setEncoding(grailsConfig.getProperty(SETTING_CONVERTERS_ENCODING, "UTF-8"));
    String defaultCirRefBehaviour = grailsConfig.getProperty(SETTING_CONVERTERS_CIRCULAR_REFERENCE_BEHAVIOUR, "DEFAULT");
    cfg.setCircularReferenceBehaviour(Converter.CircularReferenceBehaviour.valueOf(grailsConfig.getProperty(SETTING_CONVERTERS_JSON_CIRCULAR_REFERENCE_BEHAVIOUR, String.class, defaultCirRefBehaviour, Converter.CircularReferenceBehaviour.allowedValues())));
    Boolean defaultPrettyPrint = grailsConfig.getProperty(SETTING_CONVERTERS_PRETTY_PRINT, Boolean.class, false);
    Boolean prettyPrint = grailsConfig.getProperty(SETTING_CONVERTERS_JSON_PRETTY_PRINT, Boolean.class, defaultPrettyPrint);
    cfg.setPrettyPrint(prettyPrint);
    cfg.setCacheObjectMarshallerByClass(grailsConfig.getProperty(SETTING_CONVERTERS_JSON_CACHE_OBJECTS, Boolean.class, true));
    registerObjectMarshallersFromApplicationContext(cfg, JSON.class);
    ConvertersConfigurationHolder.setDefaultConfiguration(JSON.class, new ChainedConverterConfiguration<JSON>(cfg, proxyHandler));
}
Also used : Config(grails.config.Config) PropertySourcesConfig(org.grails.config.PropertySourcesConfig) ArrayList(java.util.ArrayList) JSON(grails.converters.JSON) DefaultProxyHandler(grails.core.support.proxy.DefaultProxyHandler) ProxyHandler(grails.core.support.proxy.ProxyHandler) ObjectMarshaller(org.grails.web.converters.marshaller.ObjectMarshaller)

Example 2 with ObjectMarshaller

use of org.grails.web.converters.marshaller.ObjectMarshaller in project grails-core by grails.

the class ConvertersConfigurationInitializer method initXMLConfiguration.

private void initXMLConfiguration() {
    LOG.debug("Initializing default XML Converters Configuration...");
    List<ObjectMarshaller<XML>> marshallers = new ArrayList<ObjectMarshaller<XML>>();
    marshallers.addAll(getPreviouslyConfiguredMarshallers(XML.class));
    marshallers.add(new org.grails.web.converters.marshaller.xml.Base64ByteArrayMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.ArrayMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.CollectionMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.MapMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.EnumMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.DateMarshaller());
    marshallers.add(new ProxyUnwrappingMarshaller<XML>());
    marshallers.add(new org.grails.web.converters.marshaller.xml.ToStringBeanMarshaller());
    ProxyHandler proxyHandler = getProxyHandler();
    Config grailsConfig = getGrailsConfig();
    boolean includeDomainVersion = includeDomainVersionProperty(grailsConfig, "xml");
    if (grailsConfig.getProperty(SETTING_CONVERTERS_XML_DEEP, Boolean.class, false)) {
        marshallers.add(new org.grails.web.converters.marshaller.xml.DeepDomainClassMarshaller(includeDomainVersion, proxyHandler, grailsApplication));
    } else {
        marshallers.add(new org.grails.web.converters.marshaller.xml.DomainClassMarshaller(includeDomainVersion, proxyHandler, grailsApplication));
    }
    marshallers.add(new org.grails.web.converters.marshaller.xml.GroovyBeanMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller());
    DefaultConverterConfiguration<XML> cfg = new DefaultConverterConfiguration<XML>(marshallers, proxyHandler);
    cfg.setEncoding(grailsConfig.getProperty(SETTING_CONVERTERS_ENCODING, "UTF-8"));
    String defaultCirRefBehaviour = grailsConfig.getProperty(SETTING_CONVERTERS_CIRCULAR_REFERENCE_BEHAVIOUR, "DEFAULT");
    cfg.setCircularReferenceBehaviour(Converter.CircularReferenceBehaviour.valueOf(grailsConfig.getProperty("grails.converters.xml.circular.reference.behaviour", String.class, defaultCirRefBehaviour, Converter.CircularReferenceBehaviour.allowedValues())));
    Boolean defaultPrettyPrint = grailsConfig.getProperty(SETTING_CONVERTERS_PRETTY_PRINT, Boolean.class, false);
    Boolean prettyPrint = grailsConfig.getProperty("grails.converters.xml.pretty.print", Boolean.class, defaultPrettyPrint);
    cfg.setPrettyPrint(prettyPrint);
    cfg.setCacheObjectMarshallerByClass(grailsConfig.getProperty("grails.converters.xml.cacheObjectMarshallerSelectionByClass", Boolean.class, true));
    registerObjectMarshallersFromApplicationContext(cfg, XML.class);
    ConvertersConfigurationHolder.setDefaultConfiguration(XML.class, new ChainedConverterConfiguration<XML>(cfg, proxyHandler));
}
Also used : Config(grails.config.Config) PropertySourcesConfig(org.grails.config.PropertySourcesConfig) ArrayList(java.util.ArrayList) DefaultProxyHandler(grails.core.support.proxy.DefaultProxyHandler) ProxyHandler(grails.core.support.proxy.ProxyHandler) ObjectMarshaller(org.grails.web.converters.marshaller.ObjectMarshaller) XML(grails.converters.XML)

Aggregations

Config (grails.config.Config)2 DefaultProxyHandler (grails.core.support.proxy.DefaultProxyHandler)2 ProxyHandler (grails.core.support.proxy.ProxyHandler)2 ArrayList (java.util.ArrayList)2 PropertySourcesConfig (org.grails.config.PropertySourcesConfig)2 ObjectMarshaller (org.grails.web.converters.marshaller.ObjectMarshaller)2 JSON (grails.converters.JSON)1 XML (grails.converters.XML)1