Exemplo n.º 1
0
        public void DeserializeListGivenClassAttributionAndMultipleItems()
        {
            var oddList = new ValueOrList <string> {
                "1", "3", "5"
            };
            var serialized   = JsonConvert.SerializeObject(oddList);
            var deserialized = JsonConvert.DeserializeObject <ValueOrList <string> >(serialized);

            deserialized.Should().BeEquivalentTo(oddList);
        }
Exemplo n.º 2
0
 public override void Write(Utf8JsonWriter writer, ValueOrList <T> value, JsonSerializerOptions options)
 {
     if (value == null)
     {
         JsonSerializer.Serialize(writer, null, options);
     }
     else
     {
         if (value.IsList)
         {
             JsonSerializer.Serialize(writer, value.GetList, typeof(IEnumerable <T>), options);
         }
         else
         {
             JsonSerializer.Serialize(writer, value.GetValue, typeof(T), options);
         }
     }
 }