Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Fix issue where DeserializeFn is not cleared by reset #536

Merged
merged 1 commit into from Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ServiceStack.Text/Json/JsonReader.Generic.cs
Expand Up @@ -72,6 +72,7 @@ public static void Refresh()
return;

ReadFn = JsonReader.Instance.GetParseStringSpanFn<T>();
JsConfig.AddUniqueType(typeof(T));
}

public static ParseStringDelegate GetParseFn() => ReadFn != null
Expand Down
1 change: 1 addition & 0 deletions src/ServiceStack.Text/Json/JsonWriter.Generic.cs
Expand Up @@ -167,6 +167,7 @@ public static void Refresh()
CacheFn = typeof(T) == typeof(object)
? JsonWriter.WriteLateBoundObject
: JsonWriter.Instance.GetWriteFn<T>();
JsConfig.AddUniqueType(typeof(T));
}

public static WriteObjectDelegate WriteFn()
Expand Down
1 change: 1 addition & 0 deletions src/ServiceStack.Text/Jsv/JsvReader.Generic.cs
Expand Up @@ -70,6 +70,7 @@ public static void Refresh()
return;

ReadFn = JsvReader.Instance.GetParseStringSpanFn<T>();
JsConfig.AddUniqueType(typeof(T));
}

public static ParseStringDelegate GetParseFn() => ReadFn != null
Expand Down
1 change: 1 addition & 0 deletions src/ServiceStack.Text/Jsv/JsvWriter.Generic.cs
Expand Up @@ -124,6 +124,7 @@ public static void Refresh()
CacheFn = typeof(T) == typeof(object)
? JsvWriter.WriteLateBoundObject
: JsvWriter.Instance.GetWriteFn<T>();
JsConfig.AddUniqueType(typeof(T));
}

public static WriteObjectDelegate WriteFn()
Expand Down
17 changes: 17 additions & 0 deletions tests/ServiceStack.Text.Tests/Issues/JsConfigIssues.cs
Expand Up @@ -22,6 +22,11 @@ public CustomFormatType(int value)
{
_value = value;
}

public override string ToString()
{
return _value.ToString();
}
}

class Dto
Expand All @@ -44,6 +49,18 @@ public void CallReset_AfterSerializingOnce_WithCustomSerializationForProperty_Do

TestRoundTripValue(dto);
}

[Test]
public void CallReset_AfterSerializingOnce_WithCustomSerializationForProperty_MustClearCustomSerialization()
{
var dto = new Dto { CustomFormatTypeProperty = new CustomFormatType(12345) };
JsConfig<CustomFormatType>.DeSerializeFn = str =>
new CustomFormatType(int.Parse(str));
var json = dto.ToJson();
JsConfig.Reset();
var fromJson = json.FromJson<Dto>();
Assert.That(fromJson.CustomFormatTypeProperty.Value, Is.EqualTo(0));
}

private static void ConfigureCustomFormatType()
{
Expand Down