public void serialize(Object obj, OutputStream out) throws IOException {
core.contextFactory.enterContext();
engines.set(this);
try {
// use a special ScriptableOutputStream that unwraps Wrappers
ScriptableOutputStream sout = new ScriptableOutputStream(out, core.global) {
protected Object replaceObject(Object obj) throws IOException {
if (obj instanceof HopObject)
return new HopObjectProxy((HopObject) obj);
if (obj instanceof Node)
return new HopObjectProxy((Node) obj);
if (obj instanceof GlobalObject)
return new GlobalProxy((GlobalObject) obj);
if (obj instanceof ApplicationBean)
return new ScriptBeanProxy("app");
if (obj instanceof RequestBean)
return new ScriptBeanProxy("req");
if (obj instanceof ResponseBean)
return new ScriptBeanProxy("res");
if (obj instanceof PathWrapper)
return new ScriptBeanProxy("path");
return super.replaceObject(obj);
}
};
// sout.addExcludedName("Xml");
// sout.addExcludedName("global");
sout.writeObject(obj);
sout.flush();
} finally {
Context.exit();
}
}