コード例 #1
0
 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);
 }
コード例 #2
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);
 }
コード例 #3
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);
 }
コード例 #4
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);
 }