public void CanExcludeNestedProperties() { var data = new NestedModel { Number = 1, Message = "Testing", Nested = new NestedModel { Message = "Nested", Number = 2 } }; var serializer = GetSerializer(); string json = serializer.Serialize(data, new[] { nameof(NestedModel.Number) }); Assert.Equal(@"{""message"":""Testing"",""nested"":{""message"":""Nested"",""nested"":null}}", json); }
public void CanSetMaxDepth() { var data = new NestedModel { Message = "Level 1", Nested = new NestedModel { Message = "Level 2", Nested = new NestedModel { Message = "Level 3" } } }; var serializer = GetSerializer(); string json = serializer.Serialize(data, new[] { nameof(NestedModel.Number) }, maxDepth: 2); Assert.Equal(@"{""message"":""Level 1"",""nested"":{""message"":""Level 2""}}", json); }