Пример #1
0
 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);
 }
Пример #2
0
 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);
 }
Пример #3
0
 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);
 }
Пример #4
0
 public void CanExcludeNestedProperties() {
     var data = new SampleModel { Date = DateTime.Now, Message = "Testing", Nested = new SampleModel { Date = DateTime.Now, Message = "Nested" } };
     IJsonSerializer serializer = GetSerializer();
     string json = serializer.Serialize(data, new[] { "Date" });
     Assert.Equal(@"{""Message"":""Testing"",""Nested"":{""Message"":""Nested""}}", json);
 }
Пример #5
0
 public void CanSerialize() {
     var data = new SampleModel { Date = DateTime.Now, Message = "Testing" };
     IJsonSerializer serializer = GetSerializer();
     string json = serializer.Serialize(data, new[] { "Date" });
     Assert.Equal(@"{""Message"":""Testing""}", json);
 }