diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 8b30bb77..96045e07 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -960,13 +960,23 @@ keyword such as type of business."" [Test] public void SerializeTypeProperty() { + string boolRef = typeof(bool).AssemblyQualifiedName; TypeClass typeClass = new TypeClass { TypeProperty = typeof(bool) }; string json = JsonConvert.SerializeObject(typeClass); - Assert.AreEqual(@"{""TypeProperty"":""System.Boolean""}", json); + Assert.AreEqual(@"{""TypeProperty"":""" + boolRef + @"""}", json); TypeClass typeClass2 = JsonConvert.DeserializeObject(json); Assert.AreEqual(typeof(bool), typeClass2.TypeProperty); + + string jsonSerializerTestRef = typeof(JsonSerializerTest).AssemblyQualifiedName; + typeClass = new TypeClass { TypeProperty = typeof(JsonSerializerTest) }; + + json = JsonConvert.SerializeObject(typeClass); + Assert.AreEqual(@"{""TypeProperty"":""" + jsonSerializerTestRef + @"""}", json); + + typeClass2 = JsonConvert.DeserializeObject(json); + Assert.AreEqual(typeof(JsonSerializerTest), typeClass2.TypeProperty); } [Test] diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index 4468b785..1898cd5b 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Serialization #if !SILVERLIGHT && !(converter is ComponentConverter) #endif - && (converter.GetType() != typeof(TypeConverter) || value is Type)) + && converter.GetType() != typeof(TypeConverter)) { if (converter.CanConvertTo(typeof(string))) { @@ -247,13 +247,19 @@ namespace Newtonsoft.Json.Serialization #endif #if SILVERLIGHT || PocketPC - if (value is Guid || value is Type || value is Uri || value is TimeSpan) + if (value is Guid || value is Uri || value is TimeSpan) { s = value.ToString(); return true; } #endif + if (value is Type) + { + s = ((Type)value).AssemblyQualifiedName; + return true; + } + s = null; return false; }