Reputation: 15322
I am trying to debug xml serialization. During xml serialization, the serializer "detected a circular reference". I'd like to find it and get rid of it. Is there some convenient tool / approach that I can use?
Upvotes: 5
Views: 786
Reputation: 33
$normalizers->setCircularReferenceHandler(function ($object) {
return $object->getId();
});
Upvotes: 0
Reputation: 1064204
Usually it is pretty obvious with manual inspection...
You might try serialising to a file, and just look at the end of the file - it won't be complete XML, obviously, but it should give a clue.
Note that DataContractSerializer
is capable (by enabling an option) of serialising complete graphs, but it has less XML options than XmlSerializer
has - and graph mode is even less XML-like; IMO removing the cycle is preferable. Usually this is just a case of something like:
[XmlIgnore]
public Person Parent {get;set;}
(i.e. serialize "downwards" references only)
Upvotes: 2