Skip to content

Commit

Permalink
Fix deserializing via constructor with ignored base type properties J…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Feb 11, 2023
1 parent bdeae53 commit 1ba5c13
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Argon/Serialization/JsonSerializerInternalReader.cs
Expand Up @@ -1961,6 +1961,11 @@ List<CreatorPropertyContext> ResolvePropertyAndCreatorValues(JsonObjectContract

continue;
}

if (!reader.Read())
{
throw JsonSerializationException.Create(reader, $"Unexpected end when setting {memberName}'s value.");
}
}
else
{
Expand Down
38 changes: 38 additions & 0 deletions src/Tests/Issues/Issue2708.cs
@@ -0,0 +1,38 @@
// Copyright (c) 2007 James Newton-King. All rights reserved.
// Use of this source code is governed by The MIT License,
// as found in the license.md file.

public class Issue2708 : TestFixtureBase
{
[Fact]
public void Test()
{
string json = @"
{
""Name"": ""MyName"",
""ChildClassProp"": ""MyValue"",
}";

var record = JsonConvert.DeserializeObject<MyRecord>(json);
Assert.Equal(null, record.Name); // Not set because doesn't have DataMember
Assert.Equal("MyValue", record.ChildClassProp);
}

[DataContract]
public abstract class RecordBase
{
[JsonExtensionData]
protected IDictionary<string, JToken> additionalData;

public string Name { get; set; }
}

[DataContract]
public class MyRecord : RecordBase
{
public MyRecord(string childClassProp) => ChildClassProp = childClassProp;

[DataMember]
public string ChildClassProp { get; set; }
}
}

0 comments on commit 1ba5c13

Please sign in to comment.