@@ -371,9 +371,66 @@ public void Does_escape_strings_in_JsonObject_DTO()
371371 var dto = "{\" Prop\" :{\" text\" :\" line\n break\" }}" . FromJson < JsonObjectWrapper > ( ) ;
372372 Assert . That ( dto . Prop [ "text" ] , Is . EqualTo ( "line\n break" ) ) ;
373373
374+ Assert . That ( dto . ToJson ( ) , Is . EqualTo ( "{\" Prop\" :{\" text\" :\" line\\ nbreak\" }}" ) ) ;
375+
374376 dto = "{\" Prop\" :{\" a\" :{\" text\" :\" line\n break\" }}}" . FromJson < JsonObjectWrapper > ( ) ;
375377 var a = dto . Prop . Object ( "a" ) ;
376378 Assert . That ( a [ "text" ] , Is . EqualTo ( "line\n break" ) ) ;
379+
380+ //
381+ //Assert.That(dto.ToJson(), Is.EqualTo("{\"Prop\":{\"a\":{\"text\":\"line\\nbreak\"}}}"));
382+ }
383+
384+ public class StringDictionaryWrapper
385+ {
386+ public Dictionary < string , string > Prop { get ; set ; }
387+ }
388+
389+ public class NestedStringDictionaryWrapper
390+ {
391+ public Dictionary < string , Dictionary < string , string > > Prop { get ; set ; }
377392 }
393+
394+ [ Test ]
395+ public void Does_serialize_StringDictionaryWrapper_line_breaks ( )
396+ {
397+ var prop = new Dictionary < string , string > {
398+ [ "text" ] = "line\n break"
399+ } ;
400+
401+ Assert . That ( prop . ToJson ( ) , Is . EqualTo ( "{\" text\" :\" line\\ nbreak\" }" ) ) ;
402+
403+ var dto = new StringDictionaryWrapper { Prop = prop } ;
404+ Assert . That ( dto . ToJson ( ) , Is . EqualTo ( "{\" Prop\" :{\" text\" :\" line\\ nbreak\" }}" ) ) ;
405+
406+ var nested = new NestedStringDictionaryWrapper { Prop = new Dictionary < string , Dictionary < string , string > > {
407+ [ "a" ] = prop
408+ }
409+ } ;
410+ Assert . That ( nested . ToJson ( ) , Is . EqualTo ( "{\" Prop\" :{\" a\" :{\" text\" :\" line\\ nbreak\" }}}" ) ) ;
411+ }
412+
413+ public class ObjectDictionaryWrapper
414+ {
415+ public object Prop { get ; set ; }
416+ }
417+
418+ [ Test ]
419+ public void Does_serialize_ObjectDictionaryWrapper_line_breaks ( )
420+ {
421+ var prop = new Dictionary < string , string > {
422+ [ "text" ] = "line\n break"
423+ } ;
424+
425+ var dto = new ObjectDictionaryWrapper { Prop = prop } ;
426+ Assert . That ( dto . ToJson ( ) , Is . EqualTo ( "{\" Prop\" :{\" text\" :\" line\\ nbreak\" }}" ) ) ;
427+
428+ var nested = new ObjectDictionaryWrapper { Prop = new Dictionary < string , Dictionary < string , string > > {
429+ [ "a" ] = prop
430+ }
431+ } ;
432+ Assert . That ( nested . ToJson ( ) , Is . EqualTo ( "{\" Prop\" :{\" a\" :{\" text\" :\" line\\ nbreak\" }}}" ) ) ;
433+ }
434+
378435 }
379436}
0 commit comments