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

Commit bccffc4

Browse files
committed
Fix OnDeserializationErrorTests
1 parent 6294d22 commit bccffc4

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/ServiceStack.Text/Common/DeserializeTypeRefJson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal static object StringToType(
177177
}
178178
catch (Exception e)
179179
{
180-
if (JsConfig.OnDeserializationError != null) JsConfig.OnDeserializationError(instance, propType, propertyName, propertyValueStr, e);
180+
if (JsConfig.OnDeserializationError != null) JsConfig.OnDeserializationError(instance, propType ?? typeAccessor.PropertyType, propertyName, propertyValueStr, e);
181181
if (JsConfig.ThrowOnDeserializationError) throw DeserializeTypeRef.GetSerializationException(propertyName, propertyValueStr, typeAccessor.PropertyType, e);
182182
else Tracer.Instance.WriteWarning("WARN: failed to set property {0} with: {1}", propertyName, propertyValueStr);
183183
}

src/ServiceStack.Text/Common/DeserializeTypeRefJsv.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ internal static object StringToType(
130130
}
131131
catch (Exception e)
132132
{
133-
if (JsConfig.OnDeserializationError != null) JsConfig.OnDeserializationError(instance, propType, propertyName, propertyValueStr, e);
133+
if (JsConfig.OnDeserializationError != null) JsConfig.OnDeserializationError(instance, propType ?? typeAccessor.PropertyType, propertyName, propertyValueStr, e);
134134
if (JsConfig.ThrowOnDeserializationError) throw DeserializeTypeRef.GetSerializationException(propertyName, propertyValueStr, propType, e);
135135
else Tracer.Instance.WriteWarning("WARN: failed to set property {0} with: {1}", propertyName, propertyValueStr);
136136
}

tests/ServiceStack.Text.Tests/JsonTests/OnDeserializationErrorTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Invokes_callback_deserialization_of_array_with_missing_comma()
6161
{
6262
string json = @"{""Values"": [ { ""Val"": ""a""} { ""Val"": ""b""}] }";
6363

64-
AssertThatInvalidJsonInvokesExpectedCallback<TestDtoWithArray>(json, "Values", @"[ { ""Val"": ""a""} { ""Val"": ""b""}]", typeof(TestChildDto[]), "Type definitions should start with a '{', expecting serialized type 'TestChildDto', got string starting with: Val");
64+
AssertThatInvalidJsonInvokesExpectedCallback<TestDtoWithArray>(json, "Values", @"[ { ""Val"": ""a""} { ""Val"": ""b""}]", typeof(TestChildDto[]), null);
6565
}
6666

6767
[Test]
@@ -125,7 +125,10 @@ private static void AssertThatInvalidJsonInvokesExpectedCallback<T>(string json,
125125
Assert.AreEqual(expectedProperty, property);
126126
Assert.AreEqual(expectedValue, value);
127127
Assert.AreEqual(expectedType, type);
128-
Assert.AreEqual(expectedExceptionMessage, ex.Message);
128+
if (expectedExceptionMessage != null)
129+
{
130+
Assert.AreEqual(expectedExceptionMessage, ex.Message);
131+
}
129132
Assert.IsNotNull(deserialized);
130133
Assert.IsInstanceOf<T>(deserialized);
131134
}

0 commit comments

Comments
 (0)