Avoid stack overflow in case of circular type reference

Issue: SPR-11522