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

Commit 11006a9

Browse files
committed
Imply lenient deserialization when using snake_case
1 parent 1c868c7 commit 11006a9

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/ServiceStack.Text/Common/DeserializeTypeRefJson.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ internal static object StringToType(ReadOnlySpan<char> strType,
3535
var typeAttr = config.TypeAttrMemory;
3636

3737
object instance = null;
38-
var lenient = config.PropertyConvention == PropertyConvention.Lenient;
38+
var textCase = typeConfig.TextCase.GetValueOrDefault(config.TextCase);
39+
var lenient = config.PropertyConvention == PropertyConvention.Lenient || textCase == TextCase.SnakeCase;
3940

4041
for (; index < strTypeLength; index++) { if (!JsonUtils.IsWhiteSpace(buffer[index])) break; } //Whitespace inline
4142

src/ServiceStack.Text/Common/DeserializeTypeRefJsv.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal static object StringToType(ReadOnlySpan<char> strType,
3232
var config = JsConfig.GetConfig();
3333

3434
object instance = null;
35-
var lenient = config.PropertyConvention == PropertyConvention.Lenient;
35+
var lenient = config.PropertyConvention == PropertyConvention.Lenient || config.TextCase == TextCase.SnakeCase;
3636

3737
var strTypeLength = strType.Length;
3838
while (index < strTypeLength)

src/ServiceStack.Text/TypeConfig.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ internal class TypeConfig
1414
internal FieldInfo[] Fields;
1515
internal Func<object, string, object, object> OnDeserializing;
1616
internal bool IsUserType { get; set; }
17+
internal Func<TextCase> TextCaseResolver;
18+
internal TextCase? TextCase
19+
{
20+
get
21+
{
22+
var result = TextCaseResolver?.Invoke();
23+
return result is null or Text.TextCase.Default ? null : result;
24+
}
25+
}
1726

1827
internal TypeConfig(Type type)
1928
{
@@ -77,7 +86,9 @@ public static Func<object, string, object, object> OnDeserializing
7786

7887
static TypeConfig Create()
7988
{
80-
config = new TypeConfig(typeof(T));
89+
config = new TypeConfig(typeof(T)) {
90+
TextCaseResolver = () => JsConfig<T>.TextCase
91+
};
8192

8293
var excludedProperties = JsConfig<T>.ExcludePropertyNames ?? TypeConstants.EmptyStringArray;
8394

tests/ServiceStack.Text.Tests/JsConfigTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public void TestCloneObjectWithJsConfigLocal()
131131
{
132132
JsConfig.TextCase = TextCase.Default;
133133
JsConfig<TestObject>.TextCase = TextCase.SnakeCase;
134-
JsConfig.PropertyConvention = PropertyConvention.Lenient;
135134

136135
AssertObject();
137136

0 commit comments

Comments
 (0)