[Fact]
public static void ClassWithNoSetter()
{
- // We don't attempt to deserialize into collections without a setter.
+ // We replace the contents of this collection; we don't attempt to add items to the existing collection instance.
string json = @"{""MyList"":[1,2]}";
ClassWithPopulatedListAndNoSetter obj = JsonSerializer.Deserialize<ClassWithPopulatedListAndNoSetter>(json);
Assert.Equal(1, obj.MyList.Count);
[Fact]
public static void ClassWithPopulatedList()
{
- // We don't attempt to deserialize into collections without a setter.
+ // We replace the contents of this collection; we don't attempt to add items to the existing collection instance.
string json = @"{""MyList"":[2,3]}";
ClassWithPopulatedListAndSetter obj = JsonSerializer.Deserialize<ClassWithPopulatedListAndSetter>(json);
Assert.Equal(2, obj.MyList.Count);
[InlineData(16000)]
public static async Task LargeJsonFile(int bufferSize)
{
+ const int SessionResponseCount = 100;
+
// Build up a large list to serialize.
var list = new List<SessionResponse>();
- for (int i = 0; i < 100; i++)
+ for (int i = 0; i < SessionResponseCount; i++)
{
SessionResponse response = new SessionResponse
{
// Sync case.
{
List<SessionResponse> deserializedList = JsonSerializer.Deserialize<List<SessionResponse>>(json, options);
- Assert.Equal(100, deserializedList.Count);
+ Assert.Equal(SessionResponseCount, deserializedList.Count);
string jsonSerialized = JsonSerializer.Serialize(deserializedList, options);
Assert.Equal(json, jsonSerialized);
memoryStream.Position = 0;
List<SessionResponse> deserializedList = await JsonSerializer.DeserializeAsync<List<SessionResponse>>(memoryStream, options);
- Assert.Equal(100, deserializedList.Count);
+ Assert.Equal(SessionResponseCount, deserializedList.Count);
}
}
}