Skip to content

Commit f7e2424

Browse files
committed
Change default format of Guid to use 'D' when JsConfig.SystemJsonCompatible
1 parent 7f61f09 commit f7e2424

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

ServiceStack.Text/src/ServiceStack.Text/Common/JsWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ internal static bool ShouldUseDefaultToStringMethod(Type type)
104104
return true;
105105
}
106106

107-
return underlyingType == typeof(Guid);
107+
return false;
108108
}
109109

110110
public static ITypeSerializer GetTypeSerializer<TSerializer>()

ServiceStack.Text/src/ServiceStack.Text/Common/WriteLists.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public static WriteObjectDelegate GetWriteFn()
492492

493493
var listInterface = type.GetTypeWithGenericTypeDefinitionOf(typeof(IList<>));
494494
if (listInterface == null)
495-
throw new ArgumentException(string.Format("Type {0} is not of type IList<>", type.FullName));
495+
throw new ArgumentException($"Type {type.FullName} is not of type IList<>");
496496

497497
//optimized access for regularly used types
498498
if (type == typeof(List<string>))

ServiceStack.Text/src/ServiceStack.Text/Json/JsonTypeSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ public void WriteNullableTimeSpan(TextWriter writer, object oTimeSpan)
169169
public void WriteGuid(TextWriter writer, object oValue)
170170
{
171171
var formatted = JsConfig.SystemJsonCompatible
172-
? ((Guid)oValue).ToString()
172+
? ((Guid)oValue).ToString("D")
173173
: ((Guid)oValue).ToString("N");
174174
WriteRawString(writer, formatted);
175175
}
176176

177177
public void WriteNullableGuid(TextWriter writer, object oValue)
178178
{
179179
if (oValue == null) return;
180-
WriteRawString(writer, ((Guid)oValue).ToString("N"));
180+
WriteGuid(writer, oValue);
181181
}
182182

183183
public void WriteBytes(TextWriter writer, object oByteValue)

ServiceStack.Text/src/ServiceStack.Text/Jsv/JsvTypeSerializer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,16 @@ public void WriteNullableTimeSpan(TextWriter writer, object oTimeSpan)
130130

131131
public void WriteGuid(TextWriter writer, object oValue)
132132
{
133-
writer.Write(((Guid)oValue).ToString("N"));
133+
var formatted = JsConfig.SystemJsonCompatible
134+
? ((Guid)oValue).ToString("D")
135+
: ((Guid)oValue).ToString("N");
136+
writer.Write(formatted);
134137
}
135138

136139
public void WriteNullableGuid(TextWriter writer, object oValue)
137140
{
138141
if (oValue == null) return;
139-
writer.Write(((Guid)oValue).ToString("N"));
142+
WriteGuid(writer, oValue);
140143
}
141144

142145
public void WriteBytes(TextWriter writer, object oByteValue)

0 commit comments

Comments
 (0)