diff --git a/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs b/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs index ceffe87b..4e702414 100644 --- a/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs +++ b/src/Parquet.Test/Serialisation/ParquetSerializerTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.Json.Serialization; using System.Threading.Tasks; using Parquet.Data; using Parquet.File.Values.Primitives; @@ -172,6 +173,7 @@ class Address { } class AddressBookEntry { + public string? FirstName { get; set; } public string? LastName { get; set; } @@ -557,5 +559,40 @@ public async Task Deserialize_required_strings() { Assert.Equivalent(expected, actual); } + + class AddressBookEntryAlias { + + public string? Name { get; set; } + + [JsonPropertyName("Address")] + public Address? _address { get; set; } + + [JsonPropertyName("PhoneNumbers")] + public List? _phoneNumbers { get; set; } + } + + [Fact] + public async Task List_Struct_WithAlias_Serde() { + + var data = Enumerable.Range(0, 1_000).Select(i => new AddressBookEntryAlias { + Name = "Joe", + _address = new Address() { + Country = "UK", + City = "Unknown", + }, + _phoneNumbers = new List() { + "123-456-7890", + "111-222-3333" + } + }).ToList(); + + using var ms = new MemoryStream(); + await ParquetSerializer.SerializeAsync(data, ms); + + ms.Position = 0; + IList data2 = await ParquetSerializer.DeserializeAsync(ms); + + Assert.Equivalent(data2, data); + } } } diff --git a/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs b/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs index acbf22ae..e0324405 100644 --- a/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs +++ b/src/Parquet.Test/Serialisation/SchemaReflectorTest.cs @@ -103,13 +103,24 @@ public void I_can_recognize_inherited_properties() { Assert.False(extraProp.IsArray); } - class AliasedPoco { + class AliasedPocoChild + { + [JsonPropertyName("ChildID")] + public int _id { get; set; } + } + class AliasedPoco { [JsonPropertyName("ID1")] public int _id1 { get; set; } [JsonPropertyName("ID2")] public int _id2 { get; set; } + + [JsonPropertyName("Child")] + public AliasedPocoChild? _child { get; set; } + + [JsonPropertyName("Numbers")] + public List? _numberList { get; set; } } [Fact] @@ -118,7 +129,9 @@ public void AliasedProperties() { Assert.Equal(new ParquetSchema( new DataField("ID1"), - new DataField("ID2") + new DataField("ID2"), + new StructField("Child", new DataField("ChildID")), + new ListField("Numbers", new DataField("element")) ), schema); } diff --git a/src/Parquet/Serialization/TypeExtensions.cs b/src/Parquet/Serialization/TypeExtensions.cs index 0505459c..64a980fb 100644 --- a/src/Parquet/Serialization/TypeExtensions.cs +++ b/src/Parquet/Serialization/TypeExtensions.cs @@ -136,7 +136,9 @@ private static ListField ConstructListField(string name, string propertyName, Type elementType, bool forWriting) { - return new ListField(name, MakeField(elementType, ListField.ElementName, propertyName, null, forWriting)!); + ListField lf = new ListField(name, MakeField(elementType, ListField.ElementName, propertyName, null, forWriting)!); + lf.ClrPropName = propertyName; + return lf; } private static Field? MakeField(PropertyInfo pi, bool forWriting) { @@ -190,7 +192,9 @@ private static Field MakeField(Type t, string columnName, string propertyName, if(fields.Length == 0) throw new InvalidOperationException($"property '{propertyName}' has no fields"); - return new StructField(columnName, fields); + StructField sf = new StructField(columnName, fields); + sf.ClrPropName = propertyName; + return sf; } throw new NotImplementedException();