Maybe Google JSON libraries for Java (GSON) will be useful for you:
https://code.google.com/p/google-gson/
You can use them to seriazlize/deserialize to objects as long as you deffine their classes with the proper getters and setters which have to match with the Bindings you shoud specify at eval call.
If you need to inspect the returned object attributes before serializing, deffine a class similar to this one.
public class Serializer {
static public Map<String, Object> object2Map(NativeObject o)
{
Map<String, Object> ret = new HashMap<>();
for(Object keyField: o.getAllIds())
{
try {
Object valObject = o.get(keyField.toString());
ret.put(keyField.toString(), valObject);
} catch (Exception e) {
continue;
}
}
return ret;
}
}
And use it to map the object attributes in a map.
The idea is to iterate over the object attributes and then generate an object of a specific class which can be used by GSON or generate the JSON string by yourself.