}
[Fact]
- public static void DictionaryOfObject_37569()
+ public static void DictionaryOfObject_NonPrimitiveTypes()
{
// https://github.com/dotnet/runtime/issues/29504
Dictionary<string, object> dictionary = new Dictionary<string, object>
Assert.Null(obj.MyDictionary);
}
+ // https://github.com/dotnet/runtime/issues/29933
[Fact]
- public static void Regression38643_Serialize()
+ public static void Serialize_IDictionaryOfPoco()
{
// Arrange
- var value = new Regression38643_Parent()
+ var value = new AllSingleUpperPropertiesParent()
{
- Child = new Dictionary<string, Regression38643_Child>()
+ Child = new Dictionary<string, AllSingleUpperProperties_Child>()
{
- ["1"] = new Regression38643_Child()
+ ["1"] = new AllSingleUpperProperties_Child()
{
A = "1",
B = string.Empty,
Assert.NotEmpty(actual);
}
+ // https://github.com/dotnet/runtime/issues/29933
[Fact]
- public static void Regression38643_Deserialize()
+ public static void Deserialize_IDictionaryOfPoco()
{
// Arrange
string json = "{\"child\":{\"1\":{\"a\":\"1\",\"b\":\"\",\"c\":[],\"d\":[],\"e\":null,\"f\":[],\"g\":null,\"h\":null,\"i\":null,\"j\":null,\"k\":[]}}}";
- var actual = JsonSerializer.Deserialize<Regression38643_Parent>(json, new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
+ var actual = JsonSerializer.Deserialize<AllSingleUpperPropertiesParent>(json, new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
// Assert
Assert.NotNull(actual);
Assert.Equal("1", actual.Child["1"].A);
}
+ // https://github.com/dotnet/runtime/issues/29893
[Fact]
- public static void Regression38565_Serialize()
+ public static void ShouldHandleNullInDictionaries_Serialize()
{
- var value = new Regression38565_Parent()
+ var value = new ClassWithDictionaryOfString_ChildWithDictionaryOfString()
{
Test = "value1",
- Child = new Regression38565_Child()
+ Child = new ClassWithDictionaryOfString()
};
var actual = JsonSerializer.Serialize(value);
Assert.Equal("{\"Test\":\"value1\",\"Dict\":null,\"Child\":{\"Test\":null,\"Dict\":null}}", actual);
}
+ // https://github.com/dotnet/runtime/issues/29893
[Fact]
- public static void Regression38565_Deserialize()
+ public static void ShouldHandleNullInDictionaries_Deserialize()
{
var json = "{\"Test\":\"value1\",\"Dict\":null,\"Child\":{\"Test\":null,\"Dict\":null}}";
- Regression38565_Parent actual = JsonSerializer.Deserialize<Regression38565_Parent>(json);
+ ClassWithDictionaryOfString_ChildWithDictionaryOfString actual = JsonSerializer.Deserialize<ClassWithDictionaryOfString_ChildWithDictionaryOfString>(json);
Assert.Equal("value1", actual.Test);
Assert.Null(actual.Dict);
Assert.Null(actual.Child.Test);
}
+ // https://github.com/dotnet/runtime/issues/29893
[Fact]
- public static void Regression38565_Serialize_IgnoreNullValues()
+ public static void ShouldHandleNullInDictionaries_Serialize_IgnoreNullValues()
{
- var value = new Regression38565_Parent()
+ var value = new ClassWithDictionaryOfString_ChildWithDictionaryOfString()
{
Test = "value1",
- Child = new Regression38565_Child()
+ Child = new ClassWithDictionaryOfString()
};
var actual = JsonSerializer.Serialize(value, new JsonSerializerOptions { IgnoreNullValues = true });
Assert.Equal("{\"Test\":\"value1\",\"Child\":{}}", actual);
}
+ // https://github.com/dotnet/runtime/issues/29893
[Fact]
- public static void Regression38565_Deserialize_IgnoreNullValues()
+ public static void ShouldHandleNullInDictionaries_Deserialize_IgnoreNullValues()
{
var json = "{\"Test\":\"value1\",\"Child\":{}}";
- Regression38565_Parent actual = JsonSerializer.Deserialize<Regression38565_Parent>(json);
+ ClassWithDictionaryOfString_ChildWithDictionaryOfString actual = JsonSerializer.Deserialize<ClassWithDictionaryOfString_ChildWithDictionaryOfString>(json);
Assert.Equal("value1", actual.Test);
Assert.Null(actual.Dict);
Assert.Null(actual.Child.Test);
}
+ // https://github.com/dotnet/runtime/issues/29888
[Fact]
- public static void Regression38557_Serialize()
+ public static void DictionaryWithNullShouldPreserveOrder_Serialize()
{
- var dictionaryFirst = new Regression38557_DictionaryFirst()
+ var dictionaryFirst = new ClassWithDictionaryAndProperty_DictionaryFirst()
{
Test = "value1"
};
var actual = JsonSerializer.Serialize(dictionaryFirst);
Assert.Equal("{\"Dict\":null,\"Test\":\"value1\"}", actual);
- var dictionaryLast = new Regression38557_DictionaryLast()
+ var dictionaryLast = new ClassWithDictionaryAndProperty_DictionaryLast()
{
Test = "value1"
};
Assert.Equal("{\"Test\":\"value1\",\"Dict\":null}", actual);
}
+ // https://github.com/dotnet/runtime/issues/29888
[Fact]
- public static void Regression38557_Deserialize()
+ public static void DictionaryWithNullShouldPreserveOrder_Deserialize()
{
var json = "{\"Dict\":null,\"Test\":\"value1\"}";
- Regression38557_DictionaryFirst dictionaryFirst = JsonSerializer.Deserialize<Regression38557_DictionaryFirst>(json);
+ ClassWithDictionaryAndProperty_DictionaryFirst dictionaryFirst = JsonSerializer.Deserialize<ClassWithDictionaryAndProperty_DictionaryFirst>(json);
Assert.Equal("value1", dictionaryFirst.Test);
Assert.Null(dictionaryFirst.Dict);
json = "{\"Test\":\"value1\",\"Dict\":null}";
- Regression38557_DictionaryLast dictionaryLast = JsonSerializer.Deserialize<Regression38557_DictionaryLast>(json);
+ ClassWithDictionaryAndProperty_DictionaryLast dictionaryLast = JsonSerializer.Deserialize<ClassWithDictionaryAndProperty_DictionaryLast>(json);
Assert.Equal("value1", dictionaryLast.Test);
Assert.Null(dictionaryLast.Dict);
}
+ // https://github.com/dotnet/runtime/issues/29888
[Fact]
- public static void Regression38557_Serialize_IgnoreNullValues()
+ public static void DictionaryWithNullShouldPreserveOrder_Serialize_IgnoreNullValues()
{
- var dictionaryFirst = new Regression38557_DictionaryFirst()
+ var dictionaryFirst = new ClassWithDictionaryAndProperty_DictionaryFirst()
{
Test = "value1"
};
var actual = JsonSerializer.Serialize(dictionaryFirst, new JsonSerializerOptions { IgnoreNullValues = true });
Assert.Equal("{\"Test\":\"value1\"}", actual);
- var dictionaryLast = new Regression38557_DictionaryLast()
+ var dictionaryLast = new ClassWithDictionaryAndProperty_DictionaryLast()
{
Test = "value1"
};
Assert.Equal("{\"Test\":\"value1\"}", actual);
}
+ // https://github.com/dotnet/runtime/issues/29888
[Fact]
- public static void Regression38557_Deserialize_IgnoreNullValues()
+ public static void DictionaryWithNullShouldPreserveOrder_Deserialize_IgnoreNullValues()
{
var json = "{\"Test\":\"value1\"}";
- Regression38557_DictionaryFirst dictionaryFirst = JsonSerializer.Deserialize<Regression38557_DictionaryFirst>(json);
+ ClassWithDictionaryAndProperty_DictionaryFirst dictionaryFirst = JsonSerializer.Deserialize<ClassWithDictionaryAndProperty_DictionaryFirst>(json);
Assert.Equal("value1", dictionaryFirst.Test);
Assert.Null(dictionaryFirst.Dict);
json = "{\"Test\":\"value1\"}";
- Regression38557_DictionaryLast dictionaryLast = JsonSerializer.Deserialize<Regression38557_DictionaryLast>(json);
+ ClassWithDictionaryAndProperty_DictionaryLast dictionaryLast = JsonSerializer.Deserialize<ClassWithDictionaryAndProperty_DictionaryLast>(json);
Assert.Equal("value1", dictionaryLast.Test);
Assert.Null(dictionaryLast.Dict);
[JsonIgnore] public Dictionary<int, int> MyDictionary { get; set; }
}
- public class Regression38643_Parent
+ public class AllSingleUpperPropertiesParent
{
- public IDictionary<string, Regression38643_Child> Child { get; set; }
+ public IDictionary<string, AllSingleUpperProperties_Child> Child { get; set; }
}
- public class Regression38643_Child
+ public class AllSingleUpperProperties_Child
{
public string A { get; set; }
public string B { get; set; }
public string[] K { get; set; }
}
- public class Regression38565_Parent
+ public class ClassWithDictionaryOfString_ChildWithDictionaryOfString
{
public string Test { get; set; }
public Dictionary<string, string> Dict { get; set; }
- public Regression38565_Child Child { get; set; }
+ public ClassWithDictionaryOfString Child { get; set; }
}
- public class Regression38565_Child
+ public class ClassWithDictionaryOfString
{
public string Test { get; set; }
public Dictionary<string, string> Dict { get; set; }
}
- public class Regression38557_DictionaryLast
+ public class ClassWithDictionaryAndProperty_DictionaryLast
{
public string Test { get; set; }
public Dictionary<string, string> Dict { get; set; }
}
- public class Regression38557_DictionaryFirst
+ public class ClassWithDictionaryAndProperty_DictionaryFirst
{
public Dictionary<string, string> Dict { get; set; }
public string Test { get; set; }
Converters =
{
new JsonStringEnumConverter(),
- new Types38568.MyDateTimeConverter()
+ new MyDateTimeConverter()
}
};
- Types38568.Model model = JsonSerializer.Deserialize<Types38568.Model>(json, options);
- Assert.Equal(Types38568.Color.Brown, model.EyeColor);
+ Model model = JsonSerializer.Deserialize<Model>(json, options);
+ Assert.Equal(Color.Brown, model.EyeColor);
Assert.Equal(@"http://placehold.it/32x32", model.Picture.OriginalString);
Assert.Equal(DateTime.Parse("2015-05-30T01:50:21 -01:00"), model.Registered);
}
- public class Types38568
+ // The built-in DateTime parser is stricter than DateTime.Parse.
+ public class MyDateTimeConverter : JsonConverter<DateTime>
{
- // The built-in DateTime parser is stricter than DateTime.Parse.
- public class MyDateTimeConverter : JsonConverter<DateTime>
- {
- public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
- => DateTime.Parse(reader.GetString());
+ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ => DateTime.Parse(reader.GetString());
- public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
- => writer.WriteStringValue(value.ToString("O"));
- }
+ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
+ => writer.WriteStringValue(value.ToString("O"));
+ }
- public sealed class Model
- {
- public Color EyeColor { get; set; }
- public Uri Picture { get; set; }
- public DateTime Registered { get; set; }
- }
+ public sealed class Model
+ {
+ public Color EyeColor { get; set; }
+ public Uri Picture { get; set; }
+ public DateTime Registered { get; set; }
+ }
- public enum Color
- {
- Blue,
- Green,
- Brown
- }
+ public enum Color
+ {
+ Blue,
+ Green,
+ Brown
}
}
}