This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
tests/ServiceStack.Text.Tests/JsonTests Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -7,17 +7,21 @@ public static class CollectionExtensions
77 {
88 public static ICollection < T > CreateAndPopulate < T > ( Type ofCollectionType , T [ ] withItems )
99 {
10- if ( ofCollectionType == null ) return new List < T > ( withItems ) ;
10+ if ( withItems == null )
11+ return null ;
12+
13+ if ( ofCollectionType == null )
14+ return new List < T > ( withItems ) ;
1115
1216 var genericType = ofCollectionType . FirstGenericType ( ) ;
1317 var genericTypeDefinition = genericType != null
1418 ? genericType . GetGenericTypeDefinition ( )
1519 : null ;
1620#if ! XBOX
17- if ( genericTypeDefinition == typeof ( HashSet < T > ) )
21+ if ( genericTypeDefinition == typeof ( HashSet < > ) )
1822 return new HashSet < T > ( withItems ) ;
1923#endif
20- if ( genericTypeDefinition == typeof ( LinkedList < T > ) )
24+ if ( genericTypeDefinition == typeof ( LinkedList < > ) )
2125 return new LinkedList < T > ( withItems ) ;
2226
2327 var collection = ( ICollection < T > ) ofCollectionType . CreateInstance ( ) ;
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections ;
33using System . Collections . Generic ;
4+ using System . Runtime . Serialization ;
45using System . Text ;
56using NUnit . Framework ;
67
@@ -172,5 +173,21 @@ static string DictStr(IDictionary d)
172173 foreach ( var key in d . Keys ) { sb . AppendLine ( key + " = " + d [ key ] ) ; }
173174 return sb . ToString ( ) ;
174175 }
176+
177+ public class ModelWithHashSet
178+ {
179+ public HashSet < string > Set { get ; set ; }
180+ }
181+
182+ [ Test ]
183+ public void Can_deserialize_null_Nested_HashSet ( )
184+ {
185+ JsConfig . ThrowOnDeserializationError = true ;
186+ string json = @"{""set"":null}" ;
187+ var o = json . FromJson < ModelWithHashSet > ( ) ;
188+ Assert . That ( o . Set , Is . Null ) ;
189+
190+ JsConfig . Reset ( ) ;
191+ }
175192 }
176193}
You can’t perform that action at this time.
0 commit comments