-Added ItemIsReference, ItemReferenceLoopHandling, ItemTypeNameHandling, ItemConverterType to JsonPropertyAttribute
This commit is contained in:
@@ -1006,6 +1006,74 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
Assert.IsTrue(ReferenceEquals(referenceObject.Component1, referenceObject.Component2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyItemIsReferenceObject()
|
||||
{
|
||||
TestComponentSimple c1 = new TestComponentSimple();
|
||||
|
||||
PropertyItemIsReferenceObject o1 = new PropertyItemIsReferenceObject
|
||||
{
|
||||
Data = new PropertyItemIsReferenceBody
|
||||
{
|
||||
Prop1 = c1,
|
||||
Prop2 = c1,
|
||||
Data = new List<TestComponentSimple>
|
||||
{
|
||||
c1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(o1, Formatting.Indented);
|
||||
Assert.AreEqual(@"{
|
||||
""Data"": {
|
||||
""Prop1"": {
|
||||
""$id"": ""1"",
|
||||
""MyProperty"": 0
|
||||
},
|
||||
""Prop2"": {
|
||||
""$ref"": ""1""
|
||||
},
|
||||
""Data"": {
|
||||
""$id"": ""2"",
|
||||
""$values"": [
|
||||
{
|
||||
""MyProperty"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}", json);
|
||||
|
||||
PropertyItemIsReferenceObject o2 = JsonConvert.DeserializeObject<PropertyItemIsReferenceObject>(json);
|
||||
|
||||
TestComponentSimple c2 = o2.Data.Prop1;
|
||||
TestComponentSimple c3 = o2.Data.Prop2;
|
||||
TestComponentSimple c4 = o2.Data.Data[0];
|
||||
|
||||
Assert.IsTrue(ReferenceEquals(c2, c3));
|
||||
Assert.IsFalse(ReferenceEquals(c2, c4));
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyItemIsReferenceBody
|
||||
{
|
||||
public TestComponentSimple Prop1 { get; set; }
|
||||
public TestComponentSimple Prop2 { get; set; }
|
||||
public IList<TestComponentSimple> Data { get; set; }
|
||||
}
|
||||
|
||||
public class PropertyItemIsReferenceObject
|
||||
{
|
||||
[JsonProperty(ItemIsReference = true)]
|
||||
public PropertyItemIsReferenceBody Data { get; set; }
|
||||
}
|
||||
|
||||
public class PropertyItemIsReferenceList
|
||||
{
|
||||
[JsonProperty(ItemIsReference = true)]
|
||||
public IList<IList<object>> Data { get; set; }
|
||||
}
|
||||
|
||||
[JsonArray(ItemIsReference = true)]
|
||||
|
||||
Reference in New Issue
Block a user