Merge branch 'master' of https://github.com/JamesNK/Newtonsoft.Json
This commit is contained in:
+1
-1
@@ -92,7 +92,7 @@
|
|||||||
<Topic id="SerializeDateFormatString" visible="True" title="Serialize DateFormatString" />
|
<Topic id="SerializeDateFormatString" visible="True" title="Serialize DateFormatString" />
|
||||||
<Topic id="NamingStrategyCamelCase" visible="True" title="Camel case property names" />
|
<Topic id="NamingStrategyCamelCase" visible="True" title="Camel case property names" />
|
||||||
<Topic id="NamingStrategySnakeCase" visible="True" title="Snake case property names" />
|
<Topic id="NamingStrategySnakeCase" visible="True" title="Snake case property names" />
|
||||||
<Topic id="NamingStrategySkipDictionaryKeys" visible="True" title="Configure NamingStrategy dictionary serialiation" />
|
<Topic id="NamingStrategySkipDictionaryKeys" visible="True" title="Configure NamingStrategy dictionary serialization" />
|
||||||
<Topic id="NamingStrategySkipSpecifiedNames" visible="True" title="Configure NamingStrategy property name serialization" />
|
<Topic id="NamingStrategySkipSpecifiedNames" visible="True" title="Configure NamingStrategy property name serialization" />
|
||||||
</Topic>
|
</Topic>
|
||||||
<Topic id="68b9fad2-5436-4e35-a734-9b9d751cc3e5" visible="True" noFile="true" title="LINQ to JSON">
|
<Topic id="68b9fad2-5436-4e35-a734-9b9d751cc3e5" visible="True" noFile="true" title="LINQ to JSON">
|
||||||
|
|||||||
@@ -1085,6 +1085,20 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Assert.AreEqual("1", s[0]);
|
Assert.AreEqual("1", s[0]);
|
||||||
Assert.AreEqual("2", s[1]);
|
Assert.AreEqual("2", s[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SerializeObservableCollection()
|
||||||
|
{
|
||||||
|
ObservableCollection<string> c1 = new ObservableCollection<string> { "1", "2" };
|
||||||
|
|
||||||
|
string output = JsonConvert.SerializeObject(c1);
|
||||||
|
Assert.AreEqual("[\"1\",\"2\"]", output);
|
||||||
|
|
||||||
|
ObservableCollection<string> c2 = JsonConvert.DeserializeObject<ObservableCollection<string>>(output);
|
||||||
|
Assert.AreEqual(2, c2.Count);
|
||||||
|
Assert.AreEqual("1", c2[0]);
|
||||||
|
Assert.AreEqual("2", c2[1]);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -868,7 +868,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsConcurrentCollection(Type t)
|
private static bool IsConcurrentOrObservableCollection(Type t)
|
||||||
{
|
{
|
||||||
if (t.IsGenericType())
|
if (t.IsGenericType())
|
||||||
{
|
{
|
||||||
@@ -880,6 +880,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
case "System.Collections.Concurrent.ConcurrentStack`1":
|
case "System.Collections.Concurrent.ConcurrentStack`1":
|
||||||
case "System.Collections.Concurrent.ConcurrentBag`1":
|
case "System.Collections.Concurrent.ConcurrentBag`1":
|
||||||
case "System.Collections.Concurrent.ConcurrentDictionary`2":
|
case "System.Collections.Concurrent.ConcurrentDictionary`2":
|
||||||
|
case "System.Collections.ObjectModel.ObservableCollection`1":
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -890,7 +891,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
private static bool ShouldSkipDeserialized(Type t)
|
private static bool ShouldSkipDeserialized(Type t)
|
||||||
{
|
{
|
||||||
// ConcurrentDictionary throws an error in its OnDeserialized so ignore - http://json.codeplex.com/discussions/257093
|
// ConcurrentDictionary throws an error in its OnDeserialized so ignore - http://json.codeplex.com/discussions/257093
|
||||||
if (IsConcurrentCollection(t))
|
if (IsConcurrentOrObservableCollection(t))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -907,7 +908,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private static bool ShouldSkipSerializing(Type t)
|
private static bool ShouldSkipSerializing(Type t)
|
||||||
{
|
{
|
||||||
if (IsConcurrentCollection(t))
|
if (IsConcurrentOrObservableCollection(t))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user