Recursion was creation nested objects that had a loop.

While in the recursion, the root of the object was being updated, this was causing some serialized objects to have the initial root nested in an attribute causing a loop problem when calling json_encode.

So I moved the `setRoot` to `ArrayObject` only when calling `getResult` and for nodes is okay to change it to `ArrayObject`.