-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deserializing via constructor with ignored base type properties J…
- Loading branch information
1 parent
bdeae53
commit 1ba5c13
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |