Fixed recursive objects not being encoded correctly.
Added test to detect it.