/**
* this is only to serialize the general shape and ids, to ensure that we generate the same stuff in the client
*/
@Override
public void serialize(Json json) throws IOException {
AuraContext context = Aura.getContextService().getCurrentContext();
BaseComponent<?, ?> oldComponent = context.setCurrentComponent(this);
try {
BaseComponentDef def = getComponentDef();
json.writeMapBegin();
//
// Be very careful here. descriptor != def.getDescriptor().
// This is 'case normalizing', as the client is actually case
// sensitive for descriptors (ugh!).
//
json.writeMapEntry("componentDef", def.getDescriptor());
if (!descriptor.equals(originalDescriptor)) {
json.writeMapEntry("original", originalDescriptor);
}
json.writeMapEntry("creationPath", getPath());
if ((attributeSet.getValueProvider() == null || hasProvidedAttributes) && !attributeSet.isEmpty()) {
json.writeMapEntry("attributes", attributeSet);
}
if (def.getRendererDescriptor() != null) {
RendererDef rendererDef = def.getRendererDescriptor().getDef();
if (rendererDef.isLocal()) {
StringWriter sw = new StringWriter();
rendererDef.render(this, sw);
// Not writing directly to json.appendable because then it wouldn't get escaped.
// ideally Json would have a FilterWriter that escapes that we could use here.
json.writeMapEntry("rendering", sw.toString());
}
}
if (model != null && model.getDescriptor().getDef().hasMembers()) {
json.writeMapEntry("model", model);
}
json.writeMapEnd();
} catch (QuickFixException e) {
throw new AuraRuntimeException(e);
} finally {
context.setCurrentComponent(oldComponent);
}
}