-Fixed converting XElements without namespace attribute to JSON
This commit is contained in:
@@ -374,6 +374,40 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual(7, c.ExtensionData.Count);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class MyClass
|
||||
{
|
||||
public int NotForJson { get; set; }
|
||||
|
||||
[JsonPropertyAttribute(Required = Required.Always)]
|
||||
public int ForJson { get; set; }
|
||||
|
||||
[JsonExtensionData(ReadData = true, WriteData = true)]
|
||||
public IDictionary<String, JToken> ExtraInfoJson { get; set; }
|
||||
|
||||
public MyClass(MyClass other = null)
|
||||
{
|
||||
if (other != null)
|
||||
{
|
||||
// copy construct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PopulateWithExtensionData()
|
||||
{
|
||||
string jsonStirng = @"{ ""ForJson"" : 33 , ""extra1"" : 11, ""extra2"" : 22 }";
|
||||
|
||||
MyClass c = new MyClass();
|
||||
|
||||
JsonConvert.PopulateObject(jsonStirng, c);
|
||||
|
||||
Assert.AreEqual(2, c.ExtraInfoJson.Count);
|
||||
Assert.AreEqual(11, (int)c.ExtraInfoJson["extra1"]);
|
||||
Assert.AreEqual(22, (int)c.ExtraInfoJson["extra2"]);
|
||||
}
|
||||
|
||||
public class MultipleExtensionDataAttributesTestClass
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
@@ -528,6 +528,64 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
JObject o = (JObject)actual.Payload;
|
||||
Assert.AreEqual("System.Byte[], mscorlib", (string)o["$type"]);
|
||||
Assert.AreEqual("AAECAwQFBgcICQ==", (string)o["$value"]);
|
||||
Assert.AreEqual(null, o.Parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAhead_JObject_NoParent()
|
||||
{
|
||||
ItemWithUntypedPayload actual = JsonConvert.DeserializeObject<ItemWithUntypedPayload>(@"{
|
||||
""Payload"": {}
|
||||
}",
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
|
||||
});
|
||||
|
||||
JObject o = (JObject)actual.Payload;
|
||||
Assert.AreEqual(null, o.Parent);
|
||||
}
|
||||
|
||||
public class ItemWithJTokens
|
||||
{
|
||||
public JValue Payload1 { get; set; }
|
||||
public JObject Payload2 { get; set; }
|
||||
public JArray Payload3 { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAhead_TypedJValue_NoParent()
|
||||
{
|
||||
ItemWithJTokens actual = (ItemWithJTokens)JsonConvert.DeserializeObject(@"{
|
||||
""Payload1"": 1,
|
||||
""Payload2"": {},
|
||||
""Payload3"": [1],
|
||||
""$type"": ""Newtonsoft.Json.Tests.Serialization.MetadataPropertyHandlingTests+ItemWithJTokens, Newtonsoft.Json.Tests""
|
||||
}",
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead,
|
||||
TypeNameHandling = TypeNameHandling.All
|
||||
});
|
||||
|
||||
Assert.AreEqual(null, actual.Payload1.Parent);
|
||||
Assert.AreEqual(null, actual.Payload2.Parent);
|
||||
Assert.AreEqual(null, actual.Payload3.Parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAhead_JArray_NoParent()
|
||||
{
|
||||
ItemWithUntypedPayload actual = JsonConvert.DeserializeObject<ItemWithUntypedPayload>(@"{
|
||||
""Payload"": [1]
|
||||
}",
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
|
||||
});
|
||||
|
||||
JArray o = (JArray)actual.Payload;
|
||||
Assert.AreEqual(null, o.Parent);
|
||||
}
|
||||
|
||||
public class ItemWithUntypedPayload
|
||||
|
||||
Reference in New Issue
Block a user