avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
188 stars 36 forks source link

feat: New Avro entrypoint #186

Closed Chuckame closed 2 months ago

Chuckame commented 4 months ago

Here is the new proposed avro entrypoint 🥳

Goal

Provide an unified, easy and extensible way of encoding and decoding avro. Unified and easy as it should only have methods on the Avro class (no streams, no builders, ...). Extensible as avro can be used in multiple contexts, and some requires adding some metadata (data files) or schema info (confluent schema registry, single object).

Closes #163 #141

Requirements to merge:

Breaking changes:

Tickets to open after that:

The methods

Each base method having a Schema and a SerializerStrategy or DeserializerStrategy has its related extension method to automagically get the SerializerStrategy or DeserializerStrategy and the schema from the reified type.

We now fully support java streams and ByteArray.

We are now able of streaming the avro contents with the new encodeSequence and decodeSequence methods, useful for reading avro files by example!

image image image

Example of usage

jangalinski commented 4 months ago

Seems like you are aiming for static access, while in the current version, there is a default instance (Avro.default) to use, but also the option to create a custom instance. This is quite important when working with custom logical types .. am I missing st. or would we loose the option of configuring a custom instance?

Chuckame commented 4 months ago

Seems like you are aiming for static access, while in the current version, there is a default instance (Avro.default) to use, but also the option to create a custom instance. This is quite important when working with custom logical types .. am I missing st. or would we loose the option of configuring a custom instance?

To encode in single data object mode, then you are forced to not use the default avro instance but you need to create your own instance. Avro {...} is the new constructor, exactly the same way as Json from official kotlinx format.

So to sum up, technically it's exactly the same as before (you can use the default instance Avro, that was previously Avro.default, or you can create and customize your own instance with Avro{...}, that is the same as Avro({...}), were before it was Avro(AvroConfiguration(...))), while now we have a more kotlin-esque api.