@Override
public Object call(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args) {
try {
HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
DirtyOutputStreamWriter writer = new DirtyOutputStreamWriter(response.getOutputStream(),"UTF8");
try{
new JavaScriptSerializer().serialize(args[0], Client.getCurrentObjectResponse(), writer);
}
catch(RuntimeException e){
if(writer.isDirty)
writer.write("&&");
throw e;
}
finally{
writer.flushIfDirty();
}
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
Scriptable applicationJson = new NativeObject();
objectProto.put("representation:application/json", objectProto, applicationJson);
objectProtoMirror.put("representation:application/json", objectProtoMirror, applicationJson);
objectProto.setAttributes("representation:application/json",ScriptableObject.DONTENUM);
applicationJson.put("quality", applicationJson, 0.8);
applicationJson.put("output", applicationJson, new PersevereNativeFunction(){
@Override
public Object call(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args) {
try {
HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
DirtyOutputStreamWriter writer = new DirtyOutputStreamWriter(response.getOutputStream(),"UTF8");
try{
new JSONSerializer().serialize(args[0], Client.getCurrentObjectResponse(), writer);
}
catch(RuntimeException e){
if(writer.isDirty)
writer.write("&&");
throw e;
}
finally{
writer.flushIfDirty();
}
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}