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

Commit 08e1696

Browse files
committed
Test case for renaming a field using a DataMember attribute
1 parent 596fb09 commit 08e1696

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/ServiceStack.Text.Tests/DataContractTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ public class ClassThree
188188
public string Title { get; set; }
189189
}
190190

191+
[DataContract]
192+
public class ClassFour
193+
{
194+
[DataMember(Name = "some-title")]
195+
public string Title;
196+
}
197+
191198
[Test]
192199
public void Csv_Serialize_Should_Respects_DataContract_Name()
193200
{
@@ -218,6 +225,13 @@ public void Json_Serialize_Should_Respects_DataContract_Name_When_Deserialize()
218225
Assert.That(t.Title, Is.EqualTo("right"));
219226
}
220227

228+
[Test]
229+
public void Json_Serialize_Should_Respects_DataContract_Field_Name_When_Deserialize()
230+
{
231+
var t = JsonSerializer.DeserializeFromString<ClassFour>("{\"some-title\": \"right\", \"Title\": \"wrong\"}");
232+
Assert.That(t.Title, Is.EqualTo("right"));
233+
}
234+
221235
[Test]
222236
public void Json_Serialize_Should_Respects_DataContract_Name()
223237
{

0 commit comments

Comments
 (0)