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();
}
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());
}
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));
}
Aggregations