NMS-7126: Fix circular dependencies while serializing objects to XML/JSON. Including tests.