// The ObjectTransformer interface offers all needed methods.
ObjectTransformer trans = ObjectTransformerFactory.getInstance()
.getImplementation();
// Serialize the Person object into a string.
String json = trans.serializeToJsonString(fred);
// Call PHP.
// The script converts the JSON string into an object, sets the attribute 'firstName' to 'Horst'
// and converts the object back to JSON string
InputStream convertedJson = execPHP("$person = json_decode($_ARGV[0]);$person->firstName = 'Horst'; fwrite(STDOUT, json_encode($person));", json);