public void CanExcludeProperties() { var data = new SampleModel { Date = DateTime.Now, Message = "Testing" }; IJsonSerializer serializer = GetSerializer(); string json = serializer.Serialize(data, new[] { "Date" }); Assert.Equal(@"{""message"":""Testing""}", json); }
public void WillIgnoreDefaultValues() { var data = new SampleModel { Number = 0, Bool = false }; IJsonSerializer serializer = GetSerializer(); string json = serializer.Serialize(data); Assert.Equal(@"{}", json); var model = serializer.Deserialize<SampleModel>(json); Assert.Equal(data.Number, model.Number); Assert.Equal(data.Bool, model.Bool); }
public void WillIgnoreEmptyCollections() { var data = new SampleModel { Date = DateTime.Now, Message = "Testing", Collection = new Collection<string>() }; IJsonSerializer serializer = GetSerializer(); string json = serializer.Serialize(data, new[] { "Date" }); Assert.Equal(@"{""message"":""Testing""}", json); }
public void CanSetMaxDepth() { var data = new SampleModel { Message = "Level 1", Nested = new SampleModel { Message = "Level 2", Nested = new SampleModel { Message = "Level 3" } } }; IJsonSerializer serializer = GetSerializer(); string json = serializer.Serialize(data, maxDepth: 2); Assert.Equal(@"{""message"":""Level 1"",""nested"":{""message"":""Level 2""}}", json); }