-Change Type to always be written as AssemblyQualifiedName
This commit is contained in:
@@ -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<TypeClass>(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<TypeClass>(json);
|
||||
Assert.AreEqual(typeof(JsonSerializerTest), typeClass2.TypeProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user