-Added StringEscapeHandling with options to escape HTML and non-ASCII characters
-Added feature to deserialize ISet<T> properties as HashSet<T> -Fixed ReferenceLoopHandling not being used when serializing ISerializable and dynamic values
This commit is contained in:
@@ -7154,6 +7154,68 @@ Parameter name: value",
|
||||
Assert.IsNull(c2.MyNullableDecimal);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(PORTABLE || NET20 || NET35 || WINDOWS_PHONE)
|
||||
[Test]
|
||||
public void HashSetInterface()
|
||||
{
|
||||
ISet<string> s1 = new HashSet<string>(new[] {"1", "two", "III"});
|
||||
|
||||
string json = JsonConvert.SerializeObject(s1);
|
||||
|
||||
ISet<string> s2 = JsonConvert.DeserializeObject<ISet<string>>(json);
|
||||
|
||||
Assert.AreEqual(s1.Count, s2.Count);
|
||||
foreach (string s in s1)
|
||||
{
|
||||
Assert.IsTrue(s2.Contains(s));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public class NewEmployee : Employee
|
||||
{
|
||||
public int Age { get; set; }
|
||||
|
||||
public bool ShouldSerializeName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldSerializeInheritedClassTest()
|
||||
{
|
||||
NewEmployee joe = new NewEmployee();
|
||||
joe.Name = "Joe Employee";
|
||||
joe.Age = 100;
|
||||
|
||||
Employee mike = new Employee();
|
||||
mike.Name = "Mike Manager";
|
||||
mike.Manager = mike;
|
||||
|
||||
joe.Manager = mike;
|
||||
|
||||
//StringWriter sw = new StringWriter();
|
||||
|
||||
//XmlSerializer x = new XmlSerializer(typeof(NewEmployee));
|
||||
//x.Serialize(sw, joe);
|
||||
|
||||
//Console.WriteLine(sw);
|
||||
|
||||
//JavaScriptSerializer s = new JavaScriptSerializer();
|
||||
//Console.WriteLine(s.Serialize(new {html = @"<script>hi</script>; & ! ^ * ( ) ! @ # $ % ^ ' "" - , . / ; : [ { } ] ; ' - _ = + ? ` ~ \ |"}));
|
||||
|
||||
string json = JsonConvert.SerializeObject(joe, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Age"": 100,
|
||||
""Name"": ""Joe Employee"",
|
||||
""Manager"": {
|
||||
""Name"": ""Mike Manager""
|
||||
}
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
|
||||
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
|
||||
|
||||
Reference in New Issue
Block a user