circular-reference

Is there a solution about Gson “circular reference”?

流过昼夜 提交于 2019-12-01 04:08:12
I have found many articles about the circular reference with Gson, but I can't find an elegant solution. As I know, some solutions is: Set the property that caused circular reference as "transient". exclude the property with some annotation. But as a general question, is there some common strategy to solve the problem? As far as I know there is no automated solution for circular references in Gson. The only JSON-producing library I know of that handles circular references automatically is XStream (with Jettison backend). EDIT: Jackson also supports handling of circular references with

AutoMapper: What is the difference between PreserveReferences and MaxDepth?

主宰稳场 提交于 2019-11-30 21:06:16
I'm a little bit confused. I can't find out the difference between PreserveReferences and MaxDepth . Let's suppose we have the following DTOs and models. public class PersonEntity { public PersonEntity InnerPerson { get; set; } } public class PersonModel { public PersonModel InnerPerson { get; set; } } As written in the documentation: Previously, AutoMapper could handle circular references by keeping track of what was mapped, and on every mapping, check a local hashtable of source/destination objects to see if the item was already mapped. It turns out this tracking is very expensive, and you

Any nice tools for untying knots in Haskell?

北城以北 提交于 2019-11-30 18:14:59
I've a data structure with several different types of internal circular linking, making it infinite in the sense of say the cycle command. Are there any interesting modules for collapsing such structures into flat data structures that use indexing instead? I'm interested in serializing the complete data structure, both via Read and Show as well as via Data.Serialize or similar. There are obviously nice features of building a sequential index, but an index based upon hash values of memory addresses might work fine too. This isn't really possible; there is no way to detect, from within pure code

in_array on objects with circular references

余生颓废 提交于 2019-11-30 17:44:59
I'm building an array of objects. I need this array to only contain once instance of a given object, having multiple references to the same object should throw an exception. I'm using the following code to achieve this: public function addField ($name, iface\Node $field) { // Prevent the same field being added multiple times if (!in_array ($field, $this -> fields)) { $this -> fields [$name] = $field; $field -> setParent ($this); } else { throw new \InvalidArgumentException ('This field cannot be added to this group'); } return ($this); } This started leading to problems when I started

Javascript Deep Clone Object with Circular References

…衆ロ難τιáo~ 提交于 2019-11-30 08:48:31
I have copied the function below from an existing answer by Dmitriy Pichugin. This function can deep clone an object without any circular references- it works. function deepClone( obj ) { if( !obj || true == obj ) //this also handles boolean as true and false return obj; var objType = typeof( obj ); if( "number" == objType || "string" == objType ) // add your immutables here return obj; var result = Array.isArray( obj ) ? [] : !obj.constructor ? {} : new obj.constructor(); if( obj instanceof Map ) for( var key of obj.keys() ) result.set( key, deepClone( obj.get( key ) ) ); for( var key in obj

AutoMapper: What is the difference between PreserveReferences and MaxDepth?

筅森魡賤 提交于 2019-11-30 05:42:43
问题 I'm a little bit confused. I can't find out the difference between PreserveReferences and MaxDepth . Let's suppose we have the following DTOs and models. public class PersonEntity { public PersonEntity InnerPerson { get; set; } } public class PersonModel { public PersonModel InnerPerson { get; set; } } As written in the documentation: Previously, AutoMapper could handle circular references by keeping track of what was mapped, and on every mapping, check a local hashtable of source/destination

How jQuery data() breaks circular reference

亡梦爱人 提交于 2019-11-30 05:09:15
I have read an why it's better and how it's implemented . But what i don't really understand is how does it break the circular reference? . how does it break the reference circle? $(div1).data('item', div2); $(div2).data('item', div1); like example, the divs above point to each other, how is it prevented? I have a hunch, but i just want to make sure if my hunch is right. The circular reference problem happens in some browsers when you put a reference to a DOM object on a DOM object as a property on that DOM object. Then, you have two DOM objects pointing at each other. Removing a DOM object

in_array on objects with circular references

拜拜、爱过 提交于 2019-11-30 01:51:42
问题 I'm building an array of objects. I need this array to only contain once instance of a given object, having multiple references to the same object should throw an exception. I'm using the following code to achieve this: public function addField ($name, iface\Node $field) { // Prevent the same field being added multiple times if (!in_array ($field, $this -> fields)) { $this -> fields [$name] = $field; $field -> setParent ($this); } else { throw new \InvalidArgumentException ('This field cannot

How to save an object with circular references?

不羁的心 提交于 2019-11-29 14:04:52
I want to save locally an object which has circular references. What are my options? My first thought was using HTML5 local storage but I can't stringify this object due to the circular references. Specifically I'm trying to save the DOMSelection object of the current selection. Example: var sel = window.getSelection(); var selstring = JSON.stringify(sel); // Breaks here ... localStorage.setItem("selection",selstring); The only way I could get the stringify to work now is by ignoring certain objects like so: var selstring = JSON.stringify(sel,function(k,v){ if( k=="anchorNode" || k=="baseNode"

Is It possible to perform serialization with circular references?

大兔子大兔子 提交于 2019-11-29 11:57:50
问题 So, my entity class (written in C#) follows a parent child model where every child object must have a Parent property in which it keeps reference of its Parent. This Parent property causes issues in serialization of the Object due to circular references. I can't remove the reference to parent, neither I can mark it XmlIgnore (since I need to read it back when I deserialize the XML) Any ideas on this? 回答1: XML serialization doesn't support circular references, you need to exclude the parent