@@ -44,7 +44,7 @@ public void Does_escape_string_access()
44
44
Assert . That ( jsonObject . Get ( "a" ) , Is . EqualTo ( test ) ) ;
45
45
Assert . That ( jsonObject . Get < string > ( "a" ) , Is . EqualTo ( test ) ) ;
46
46
47
- Assert . That ( jsonObject . GetUnescaped ( "a" ) , Is . EqualTo ( test . Replace ( "\" " , "\\ \" " ) ) ) ;
47
+ Assert . That ( jsonObject . GetUnescaped ( "a" ) , Is . EqualTo ( test . Replace ( "\" " , "\\ \" " ) ) ) ;
48
48
}
49
49
50
50
[ Test ]
@@ -174,7 +174,7 @@ public class TypeObject
174
174
public bool Prop3 { get ; set ; }
175
175
public double Prop4 { get ; set ; }
176
176
public string [ ] Prop5 { get ; set ; }
177
- public Dictionary < string , string > Prop6 { get ; set ; }
177
+ public Dictionary < string , string > Prop6 { get ; set ; }
178
178
}
179
179
180
180
[ Test ]
@@ -195,8 +195,8 @@ public void Can_parse_dynamic_json()
195
195
Assert . That ( typeObj . Prop2 , Is . EqualTo ( 33 ) ) ;
196
196
Assert . That ( typeObj . Prop3 , Is . EqualTo ( true ) ) ;
197
197
Assert . That ( typeObj . Prop4 , Is . EqualTo ( 6.3d ) ) ;
198
- Assert . That ( typeObj . Prop5 , Is . EquivalentTo ( new [ ] { "A" , "B" , "C" } ) ) ;
199
- Assert . That ( typeObj . Prop6 , Is . EquivalentTo ( new Dictionary < string , string > { { "A" , "a" } } ) ) ;
198
+ Assert . That ( typeObj . Prop5 , Is . EquivalentTo ( new [ ] { "A" , "B" , "C" } ) ) ;
199
+ Assert . That ( typeObj . Prop6 , Is . EquivalentTo ( new Dictionary < string , string > { { "A" , "a" } } ) ) ;
200
200
201
201
var obj = JsonObject . Parse ( json ) ;
202
202
@@ -217,5 +217,73 @@ public void Can_parse_dynamic_json()
217
217
Assert . That ( o . Prop5 , Is . EquivalentTo ( new [ ] { "A" , "B" , "C" } ) ) ;
218
218
Assert . That ( o . Prop6 , Is . EquivalentTo ( new Dictionary < string , string > { { "A" , "a" } } ) ) ;
219
219
}
220
+
221
+ [ Test ]
222
+ public void Can_deserialize_array_string_in_Map ( )
223
+ {
224
+ var json = "{\" name\" :\" foo\" ,\" roles\" :[\" Role1\" ,\" Role 2\" ]}" ;
225
+ var obj = JsonObject . Parse ( json ) ;
226
+ Assert . That ( obj . GetArray < string > ( "roles" ) , Is . EqualTo ( new [ ] { "Role1" , "Role 2" } ) ) ;
227
+
228
+ var map = json . FromJson < Dictionary < string , string > > ( ) ;
229
+ Assert . That ( map . GetArray < string > ( "roles" ) , Is . EqualTo ( new [ ] { "Role1" , "Role 2" } ) ) ;
230
+ }
231
+
232
+ [ Test ]
233
+ public void Can_deserialize_array_numbers_in_Map ( )
234
+ {
235
+ var json = "{\" name\" :\" foo\" ,\" roles\" :[1,2]}" ;
236
+ var obj = JsonObject . Parse ( json ) ;
237
+ Assert . That ( obj . GetArray < int > ( "roles" ) , Is . EqualTo ( new [ ] { 1 , 2 } ) ) ;
238
+
239
+ var map = json . FromJson < Dictionary < string , string > > ( ) ;
240
+ Assert . That ( map . GetArray < int > ( "roles" ) , Is . EqualTo ( new [ ] { 1 , 2 } ) ) ;
241
+ }
242
+
243
+ public class TestJArray
244
+ {
245
+ public int Id { get ; set ; }
246
+ public string Name { get ; set ; }
247
+
248
+ protected bool Equals ( TestJArray other )
249
+ {
250
+ return Id == other . Id && string . Equals ( Name , other . Name ) ;
251
+ }
252
+
253
+ public override bool Equals ( object obj )
254
+ {
255
+ if ( ReferenceEquals ( null , obj ) ) return false ;
256
+ if ( ReferenceEquals ( this , obj ) ) return true ;
257
+ if ( obj . GetType ( ) != this . GetType ( ) ) return false ;
258
+ return Equals ( ( TestJArray ) obj ) ;
259
+ }
260
+
261
+ public override int GetHashCode ( )
262
+ {
263
+ unchecked
264
+ {
265
+ return ( Id * 397 ) ^ ( Name != null ? Name . GetHashCode ( ) : 0 ) ;
266
+ }
267
+ }
268
+ }
269
+
270
+ [ Test ]
271
+ public void Can_deserialize_array_objects_in_Map ( )
272
+ {
273
+ var json = "{\" name\" :\" foo\" ,\" roles\" :[{\" Id\" :1,\" Name\" :\" Role1\" },{\" Id\" :2,\" Name\" :\" Role 2\" }]}" ;
274
+ var obj = JsonObject . Parse ( json ) ;
275
+ Assert . That ( obj . GetArray < TestJArray > ( "roles" ) , Is . EqualTo ( new [ ]
276
+ {
277
+ new TestJArray { Id = 1 , Name = "Role1" } ,
278
+ new TestJArray { Id = 2 , Name = "Role 2" } ,
279
+ } ) ) ;
280
+
281
+ var map = json . FromJson < Dictionary < string , string > > ( ) ;
282
+ Assert . That ( map . GetArray < TestJArray > ( "roles" ) , Is . EqualTo ( new [ ]
283
+ {
284
+ new TestJArray { Id = 1 , Name = "Role1" } ,
285
+ new TestJArray { Id = 2 , Name = "Role 2" } ,
286
+ } ) ) ;
287
+ }
220
288
}
221
289
}
0 commit comments