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

Commit ea9d6e2

Browse files
committed
Ignore __type attr when trying to deserialize into KVP
1 parent 3625680 commit ea9d6e2

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/ServiceStack.Text/Common/DeserializeKeyValuePair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static object ParseKeyValuePair<TKey, TValue>(
7474
keyValue = (TKey)parseKeyFn(keyElementValue);
7575
else if (key.CompareIgnoreCase("value".AsSpan()))
7676
valueValue = (TValue)parseValueFn(keyElementValue);
77-
else
77+
else if (!key.SequenceEqual(JsConfig.TypeAttr.AsSpan()))
7878
throw new SerializationException("Incorrect KeyValuePair property: " + key.ToString());
7979

8080
Serializer.EatItemSeperatorOrMapEndChar(value, ref index);

tests/ServiceStack.Text.Tests/RuntimeSerializationTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,14 @@ private class MyProperty : IProperty
332332
{
333333
public string Value { get; set; }
334334
}
335+
336+
[Test]
337+
public void Can_deserialize_object_into_string_dictionary()
338+
{
339+
var json = "{\"__type\":\"System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib],[System.String, System.Private.CoreLib]], System.Private.CoreLib\",\"Key\":\"A\",\"Value\":\"B\"}";
340+
var dto = json.FromJson<KeyValuePair<string, string>>();
341+
Assert.That(dto.Key, Is.EqualTo("A"));
342+
Assert.That(dto.Value, Is.EqualTo("B"));
343+
}
335344
}
336345
}

0 commit comments

Comments
 (0)