This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -176,5 +176,45 @@ public void Can_limit_cyclical_dependencies()
176
176
p . ToJson ( ) . Print ( ) ;
177
177
}
178
178
}
179
+
180
+ class Node
181
+ {
182
+ public string Name { get ; set ; }
183
+
184
+ [ IgnoreDataMember ]
185
+ public Node Parent { get ; set ; }
186
+
187
+ public List < Node > Children { get ; set ; }
188
+ }
189
+
190
+ [ Test ]
191
+ public void Ignore_Cyclical_dependencies ( )
192
+ {
193
+ JsConfig < Node > . OnDeserializedFn = ( node ) =>
194
+ {
195
+ node . Children . Each ( child => child . Parent = node ) ;
196
+ return node ;
197
+ } ;
198
+
199
+ var parent = new Node
200
+ {
201
+ Name = "Parent" ,
202
+ } ;
203
+ parent . Children = new List < Node >
204
+ {
205
+ new Node { Name = "Child" , Parent = parent } ,
206
+ } ;
207
+
208
+ var json = parent . ToJson ( ) ;
209
+ Assert . That ( json ,
210
+ Is . EqualTo ( "{\" Name\" :\" Parent\" ,\" Children\" :[{\" Name\" :\" Child\" }]}" ) ) ;
211
+
212
+ var fromJson = json . FromJson < Node > ( ) ;
213
+
214
+ Assert . That ( fromJson . Children [ 0 ] . Parent , Is . EqualTo ( fromJson ) ) ;
215
+
216
+ JsConfig < Node > . OnDeserializedFn = null ;
217
+ JsConfig . Reset ( ) ;
218
+ }
179
219
}
180
220
}
You can’t perform that action at this time.
0 commit comments