Search in sources :

Example 1 with EntityProxyHandler

use of grails.core.support.proxy.EntityProxyHandler in project grails-core by grails.

the class DomainClassMarshaller method asShortObject.

protected void asShortObject(Object refObj, JSON json, GrailsDomainClassProperty idProperty, GrailsDomainClass referencedDomainClass) throws ConverterException {
    Object idValue;
    if (proxyHandler instanceof EntityProxyHandler) {
        idValue = ((EntityProxyHandler) proxyHandler).getProxyIdentifier(refObj);
        if (idValue == null) {
            idValue = extractValue(refObj, idProperty);
        }
    } else {
        idValue = extractValue(refObj, idProperty);
    }
    JSONWriter writer = json.getWriter();
    writer.object();
    if (isIncludeClass()) {
        writer.key("class").value(referencedDomainClass.getFullName());
    }
    if (idValue != null) {
        writer.key("id").value(idValue);
    }
    writer.endObject();
}
Also used : JSONWriter(org.grails.web.json.JSONWriter) EntityProxyHandler(grails.core.support.proxy.EntityProxyHandler) GroovyObject(groovy.lang.GroovyObject)

Example 2 with EntityProxyHandler

use of grails.core.support.proxy.EntityProxyHandler in project grails-core by grails.

the class XML method getElementName.

public String getElementName(Object o) {
    ObjectMarshaller<XML> om = config.getMarshaller(o);
    if (om instanceof NameAwareMarshaller) {
        return ((NameAwareMarshaller) om).getElementName(o);
    }
    final ProxyHandler proxyHandler = config.getProxyHandler();
    if (proxyHandler.isProxy(o) && (proxyHandler instanceof EntityProxyHandler)) {
        EntityProxyHandler entityProxyHandler = (EntityProxyHandler) proxyHandler;
        final Class<?> cls = entityProxyHandler.getProxiedClass(o);
        return GrailsNameUtils.getPropertyName(cls);
    }
    return GrailsNameUtils.getPropertyName(o.getClass());
}
Also used : EntityProxyHandler(grails.core.support.proxy.EntityProxyHandler) EntityProxyHandler(grails.core.support.proxy.EntityProxyHandler) ProxyHandler(grails.core.support.proxy.ProxyHandler) NameAwareMarshaller(org.grails.web.converters.marshaller.NameAwareMarshaller)

Example 3 with EntityProxyHandler

use of grails.core.support.proxy.EntityProxyHandler in project grails-core by grails.

the class DomainClassMarshaller method asShortObject.

protected void asShortObject(Object refObj, XML xml, GrailsDomainClassProperty idProperty, GrailsDomainClass referencedDomainClass) throws ConverterException {
    Object idValue;
    if (proxyHandler instanceof EntityProxyHandler) {
        idValue = ((EntityProxyHandler) proxyHandler).getProxyIdentifier(refObj);
        if (idValue == null) {
            ClassPropertyFetcher propertyFetcher = ClassPropertyFetcher.forClass(refObj.getClass());
            idValue = propertyFetcher.getPropertyValue(refObj, idProperty.getName());
        }
    } else {
        ClassPropertyFetcher propertyFetcher = ClassPropertyFetcher.forClass(refObj.getClass());
        idValue = propertyFetcher.getPropertyValue(refObj, idProperty.getName());
    }
    xml.attribute(GrailsDomainClassProperty.IDENTITY, String.valueOf(idValue));
}
Also used : EntityProxyHandler(grails.core.support.proxy.EntityProxyHandler) ClassPropertyFetcher(org.grails.datastore.mapping.reflect.ClassPropertyFetcher)

Aggregations

EntityProxyHandler (grails.core.support.proxy.EntityProxyHandler)3 ProxyHandler (grails.core.support.proxy.ProxyHandler)1 GroovyObject (groovy.lang.GroovyObject)1 ClassPropertyFetcher (org.grails.datastore.mapping.reflect.ClassPropertyFetcher)1 NameAwareMarshaller (org.grails.web.converters.marshaller.NameAwareMarshaller)1 JSONWriter (org.grails.web.json.JSONWriter)1