This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +21
-0
lines changed
tests/ServiceStack.Text.Tests/Issues Expand file tree Collapse file tree 5 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ public static void Refresh()
7272 return ;
7373
7474 ReadFn = JsonReader . Instance . GetParseStringSpanFn < T > ( ) ;
75+ JsConfig . AddUniqueType ( typeof ( T ) ) ;
7576 }
7677
7778 public static ParseStringDelegate GetParseFn ( ) => ReadFn != null
Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ public static void Refresh()
167167 CacheFn = typeof ( T ) == typeof ( object )
168168 ? JsonWriter . WriteLateBoundObject
169169 : JsonWriter . Instance . GetWriteFn < T > ( ) ;
170+ JsConfig . AddUniqueType ( typeof ( T ) ) ;
170171 }
171172
172173 public static WriteObjectDelegate WriteFn ( )
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ public static void Refresh()
7070 return ;
7171
7272 ReadFn = JsvReader . Instance . GetParseStringSpanFn < T > ( ) ;
73+ JsConfig . AddUniqueType ( typeof ( T ) ) ;
7374 }
7475
7576 public static ParseStringDelegate GetParseFn ( ) => ReadFn != null
Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ public static void Refresh()
124124 CacheFn = typeof ( T ) == typeof ( object )
125125 ? JsvWriter . WriteLateBoundObject
126126 : JsvWriter . Instance . GetWriteFn < T > ( ) ;
127+ JsConfig . AddUniqueType ( typeof ( T ) ) ;
127128 }
128129
129130 public static WriteObjectDelegate WriteFn ( )
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ public CustomFormatType(int value)
2222 {
2323 _value = value ;
2424 }
25+
26+ public override string ToString ( )
27+ {
28+ return _value . ToString ( ) ;
29+ }
2530 }
2631
2732 class Dto
@@ -44,6 +49,18 @@ public void CallReset_AfterSerializingOnce_WithCustomSerializationForProperty_Do
4449
4550 TestRoundTripValue ( dto ) ;
4651 }
52+
53+ [ Test ]
54+ public void CallReset_AfterSerializingOnce_WithCustomSerializationForProperty_MustClearCustomSerialization ( )
55+ {
56+ var dto = new Dto { CustomFormatTypeProperty = new CustomFormatType ( 12345 ) } ;
57+ JsConfig < CustomFormatType > . DeSerializeFn = str =>
58+ new CustomFormatType ( int . Parse ( str ) ) ;
59+ var json = dto . ToJson ( ) ;
60+ JsConfig . Reset ( ) ;
61+ var fromJson = json . FromJson < Dto > ( ) ;
62+ Assert . That ( fromJson . CustomFormatTypeProperty . Value , Is . EqualTo ( 0 ) ) ;
63+ }
4764
4865 private static void ConfigureCustomFormatType ( )
4966 {
You can’t perform that action at this time.
0 commit comments