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

Commit 376f1ff

Browse files
committed
Show how to deserialize json with_underscores into C# POCO
1 parent b49ded2 commit 376f1ff

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
34
using System.Linq;
45
using NUnit.Framework;
@@ -205,5 +206,31 @@ public void Can_detect_dto_with_no_Version()
205206
Assert.That(fromDto1.Name, Is.EqualTo("Foo 1"));
206207
}
207208
}
209+
210+
public class ErrorPoco
211+
{
212+
public string ErrorCode { get; set; }
213+
public string ErrorDescription { get; set; }
214+
}
215+
216+
[Test]
217+
public void Can_deserialize_json_with_underscores()
218+
{
219+
var json = "{\"error_code\":\"anErrorCode\",\"error_description\",\"the description\"}";
220+
221+
var dto = json.FromJson<ErrorPoco>();
222+
223+
Assert.That(dto.ErrorCode, Is.Null);
224+
225+
using (JsConfig.With(propertyConvention: PropertyConvention.Lenient))
226+
{
227+
dto = json.FromJson<ErrorPoco>();
228+
229+
Assert.That(dto.ErrorCode, Is.EqualTo("anErrorCode"));
230+
Assert.That(dto.ErrorDescription, Is.EqualTo("the description"));
231+
232+
dto.PrintDump();
233+
}
234+
}
208235
}
209236
}

0 commit comments

Comments
 (0)