-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deserialization of additional repeated list
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/Protobuf.System.Text.Json.Tests/Protos/schema_evolution.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto3"; | ||
|
||
option csharp_namespace = "System.Text.Json.Protobuf.Tests"; | ||
|
||
message SchemaEvolutionV1 { | ||
int32 property_1 = 1; | ||
} | ||
|
||
message SchemaEvolutionV2 { | ||
int32 property_1 = 1; | ||
repeated int32 property_2 = 2; | ||
} |
32 changes: 32 additions & 0 deletions
32
test/Protobuf.System.Text.Json.Tests/SchemaEvolutionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Protobuf.Tests; | ||
using Protobuf.System.Text.Json.Tests.Utils; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Protobuf.System.Text.Json.Tests; | ||
|
||
public class SchemaEvolutionTests | ||
{ | ||
[Fact] | ||
public void Should_be_able_to_deserialize_array_of_schema_v2_to_array_of_schema_v1_when_schema_v2_has_additional_repeated_field() | ||
{ | ||
// Arrange | ||
var schemaEvolutionV2 = new[] | ||
{ | ||
new SchemaEvolutionV2 | ||
{ | ||
Property1 = 1, | ||
Property2 = { 2, 3 } | ||
} | ||
}; | ||
var jsonSerializerOptions = TestHelper.CreateJsonSerializerOptions(); | ||
var serialized = JsonSerializer.Serialize(schemaEvolutionV2, jsonSerializerOptions); | ||
|
||
// Act | ||
var deserialized = JsonSerializer.Deserialize<SchemaEvolutionV1[]>(serialized, jsonSerializerOptions); | ||
|
||
// Assert | ||
deserialized.ShouldHaveSingleItem(); | ||
} | ||
} |