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

Commit b309a61

Browse files
committed
Fix bug regression re-added in commit cb76ac
1 parent 53cf397 commit b309a61

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

NuGet/servicestack.text.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
44
<id>ServiceStack.Text</id>
55
<title>.NET's fastest JSON Serializer by ServiceStack</title>
6-
<version>3.9.53</version>
6+
<version>3.9.54</version>
77
<authors>Demis Bellot</authors>
88
<owners>Demis Bellot</owners>
99
<summary>.NET's fastest JSON, JSV and CSV Text Serializers</summary>

src/ServiceStack.Text/Json/JsonTypeSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ public void WriteDecimal(TextWriter writer, object decimalValue)
288288
public void WriteEnum(TextWriter writer, object enumValue)
289289
{
290290
if (enumValue == null) return;
291-
if (JsConfig.TreatEnumAsInteger)
291+
if (GetTypeInfo(enumValue.GetType()).IsNumeric)
292292
JsWriter.WriteEnumFlags(writer, enumValue);
293293
else
294-
writer.Write(enumValue);
294+
WriteRawString(writer, enumValue.ToString());
295295
}
296296

297297
public void WriteEnumFlags(TextWriter writer, object enumFlagValue)

src/ServiceStack.Text/Json/JsonWriter.Generic.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ public static WriteObjectDelegate GetValueTypeToStringMethod(Type type)
130130

131131
internal class TypeInfo
132132
{
133-
internal bool EncodeMapKey;
134-
}
133+
internal bool EncodeMapKey;
134+
internal bool IsNumeric;
135+
}
135136

136137
/// <summary>
137138
/// Implement the serializer using a more static approach
@@ -163,8 +164,10 @@ public static TypeInfo GetTypeInfo()
163164

164165
static JsonWriter()
165166
{
167+
var isNumeric = typeof(T).IsNumericType();
166168
TypeInfo = new TypeInfo {
167-
EncodeMapKey = typeof(T) == typeof(bool) || typeof(T).IsNumericType()
169+
EncodeMapKey = typeof(T) == typeof(bool) || isNumeric,
170+
IsNumeric = isNumeric
168171
};
169172

170173
CacheFn = typeof(T) == typeof(object)

src/ServiceStack.Text/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("3.9.53.0")]
34+
[assembly: AssemblyVersion("3.9.54.0")]
3535
//[assembly: AssemblyFileVersion("1.0.0.0")]

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public static bool IsNumericType(this Type type)
150150
{
151151
if (type == null) return false;
152152

153+
if (type.IsEnum) //TypeCode can be TypeCode.Int32
154+
{
155+
return JsConfig.TreatEnumAsInteger || type.IsEnumFlags();
156+
}
157+
153158
switch (Type.GetTypeCode(type))
154159
{
155160
case TypeCode.Byte:
@@ -172,7 +177,7 @@ public static bool IsNumericType(this Type type)
172177
}
173178
if (type.IsEnum)
174179
{
175-
return type.IsEnumFlags();
180+
return JsConfig.TreatEnumAsInteger || type.IsEnumFlags();
176181
}
177182
return false;
178183
}

tests/ServiceStack.Text.Tests/AdhocModelTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ public class DictionaryEnumType
534534
[Test]
535535
public void Can_Serialize_Dictionary_With_Enums()
536536
{
537-
538537
Dictionary<EnumValues, Test> dictEnumType =
539538
new Dictionary<EnumValues, Test>
540539
{

0 commit comments

Comments
 (0)