-Change Type to always be written as AssemblyQualifiedName
This commit is contained in:
@@ -960,13 +960,23 @@ keyword such as type of business.""
|
|||||||
[Test]
|
[Test]
|
||||||
public void SerializeTypeProperty()
|
public void SerializeTypeProperty()
|
||||||
{
|
{
|
||||||
|
string boolRef = typeof(bool).AssemblyQualifiedName;
|
||||||
TypeClass typeClass = new TypeClass { TypeProperty = typeof(bool) };
|
TypeClass typeClass = new TypeClass { TypeProperty = typeof(bool) };
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(typeClass);
|
string json = JsonConvert.SerializeObject(typeClass);
|
||||||
Assert.AreEqual(@"{""TypeProperty"":""System.Boolean""}", json);
|
Assert.AreEqual(@"{""TypeProperty"":""" + boolRef + @"""}", json);
|
||||||
|
|
||||||
TypeClass typeClass2 = JsonConvert.DeserializeObject<TypeClass>(json);
|
TypeClass typeClass2 = JsonConvert.DeserializeObject<TypeClass>(json);
|
||||||
Assert.AreEqual(typeof(bool), typeClass2.TypeProperty);
|
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]
|
[Test]
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
&& !(converter is ComponentConverter)
|
&& !(converter is ComponentConverter)
|
||||||
#endif
|
#endif
|
||||||
&& (converter.GetType() != typeof(TypeConverter) || value is Type))
|
&& converter.GetType() != typeof(TypeConverter))
|
||||||
{
|
{
|
||||||
if (converter.CanConvertTo(typeof(string)))
|
if (converter.CanConvertTo(typeof(string)))
|
||||||
{
|
{
|
||||||
@@ -247,13 +247,19 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SILVERLIGHT || PocketPC
|
#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();
|
s = value.ToString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (value is Type)
|
||||||
|
{
|
||||||
|
s = ((Type)value).AssemblyQualifiedName;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
s = null;
|
s = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user