Skip to content

AvroConvert 4.0.0-preview.4

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 02 Nov 13:13
· 21 commits to master since this release
702aa75

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 string field 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.
  • DateTime reads and writes date, TimeSpan reads and writes time-millis / time-micros, the same types as in classes generated by avrogen.
  • GenerateModel (and avroconvert compile schema) keeps the whole schema: [DataContract(Namespace)], [DataMember], [AvroDecimal(Precision, Scale)], [AvroType] for timestamp-millis / time-millis, using directives. date gives DateOnly, time-* gives TimeOnly. The classes give back the same schema.
  • IDictionary<string, T> and IReadOnlyDictionary<string, T> members are Avro maps. SortedDictionary, ReadOnlyDictionary and classes deriving from Dictionary are 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> (also IDictionary / 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);
  • object members, List<object>, Dictionary<string, object> and ExpandoObject take their schema from the values. A string in them threw, and a class lost its fields without an error.
  • AvroSchema.FromValue and AvroSchema.FromItems give the schema of values of type object.
  • A union takes the branch of exactly the value's type first: a double next to a long branch is not cut to 2, a DateTime next to a date branch keeps its time.

Fixes

  • Merge of files written with CollectionMode = SingleArray, and of files written with another class than T
  • 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, a CodecType or a file path are hidden from IntelliSense and still work. The text overloads of Avro2JsonEncoding / JsonEncoding2Avro added in the previews are removed, use AvroSchema.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).
  • GenerateModel gives DateOnly / TimeOnly instead of DateTime / TimeSpan for date / time-*.

Full list: CHANGELOG · Licence: LICENSE.md · https://soltechnology.dev/avroconvert/