Fix stack overflow error when serializing complex object graph

Track visited objects during serialization to prevent stack overflows. Prevents serializer from getting stuck in endless loops by not revisiting objects.  Related to scriptcs bug:  https://github.com/scriptcs/scriptcs/issues/255