Repository navigation
AvroConvert 4.0.0-preview.4
Pre-release
Pre-release
·
21 commits
to master
since this release
The fourth 4.0 preview is about moving from other libraries and about data without a class. It reads what Chr.Avro and Apache.Avro write, reads a record into a dictionary, and writes your own keys into the file header. Please try it on your data and report anything that behaves differently than 3.4.x or the previous previews.
dotnet add package AvroConvert --prerelease
Coming from Chr.Avro or Apache.Avro
- Dates and times in a
stringfield are read and written as ISO 8601 text, like Chr.Avro writes them by default:DateTime,DateTimeOffset,DateOnly,TimeOnly,TimeSpan("PT1H30M"). Topics written by Chr.Avro can be read without a schema change. DateTimereads and writesdate,TimeSpanreads and writestime-millis/time-micros, the same types as in classes generated byavrogen.GenerateModel(andavroconvert compile schema) keeps the whole schema:[DataContract(Namespace)],[DataMember],[AvroDecimal(Precision, Scale)],[AvroType]fortimestamp-millis/time-millis,usingdirectives.dategivesDateOnly,time-*givesTimeOnly. The classes give back the same schema.IDictionary<string, T>andIReadOnlyDictionary<string, T>members are Avro maps.SortedDictionary,ReadOnlyDictionaryand classes deriving fromDictionaryare read back too.- Field and record aliases work on read: a field renamed with
[DataMember(Name)]reads the data written with the old name.
Data without a class
- A record can be read into
Dictionary<string, object>(alsoIDictionary/IReadOnlyDictionary), with nested records as dictionaries (#197):
var order = AvroConvert.Deserialize<Dictionary<string, object>>(avro);
var city = ((Dictionary<string, object>)order["Address"])["City"];- Own keys in the container header and
AvroConvert.GetMetadata(#196):
var keys = new Dictionary<string, AvroMetadataValue> { ["format-version"] = "2" };
byte[] avro = AvroConvert.Serialize(entries, AvroSchema.Create<Entry>(), metadata: keys);
var header = AvroConvert.GetMetadata(avro);objectmembers,List<object>,Dictionary<string, object>andExpandoObjecttake their schema from the values. A string in them threw, and a class lost its fields without an error.AvroSchema.FromValueandAvroSchema.FromItemsgive the schema of values of typeobject.- A union takes the branch of exactly the value's type first: a
doublenext to alongbranch is not cut to2, aDateTimenext to adatebranch keeps its time.
Fixes
Mergeof files written withCollectionMode = SingleArray, and of files written with another class thanT- A union of records on read picks the branch by name or alias first, then the first record the data fits, the same rule as outside a union
- Nullable struct records (
Point?) - A recursive record read into
dynamic, data nested too deep and reference cycles throw instead of ending the process OpenDeserializer<ExpandoObject>returned objects without fields- Schemas keep attributes the specification does not define (e.g.
field-id) and enum aliases
Breaking changes against the previous previews
- One way to give a schema (
AvroSchema) and a codec (AvroConvertOptions). The overloads taking the schema as text, aCodecTypeor a file path are hidden from IntelliSense and still work. The text overloads ofAvro2JsonEncoding/JsonEncoding2Avroadded in the previews are removed, useAvroSchema.Parse. - Some overloads are merged into one with optional parameters. The calls compile as before, but code compiled against a preview has to be rebuilt.
DeserializeHeadless(bytes, writer, reader, type)reads all the rows, like the generic overload (#69).GenerateModelgivesDateOnly/TimeOnlyinstead ofDateTime/TimeSpanfordate/time-*.
Full list: CHANGELOG · Licence: LICENSE.md · https://soltechnology.dev/avroconvert/