Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Option of sum types #450

Merged
merged 4 commits into from
Nov 23, 2022

Conversation

erikvanoosten
Copy link
Contributor

@erikvanoosten erikvanoosten commented May 11, 2022

The type Option[A] for any sum type A should be supported. Right now this fails with org.apache.avro.AvroRuntimeException: Nested union (see #442 problem 1).

This is because Codec[Option[_]] is build from a UnionCodec which references a nested UnionCodec. We solve the problem by creating a special Codec for Options.

The type `Option[A]` for any sum type `A` should be supported. Right now this fails with `org.apache.avro.AvroRuntimeException: Nested union` (see fd4s#442 problem 1).

This is because `Codec[Option[_]]` is build from a `UnionCodec`. We solve the problem by creating a special `Codec` for `Option`s.
@erikvanoosten erikvanoosten changed the title Support Option of sum types (work in progress) Support Option of sum types (feedback requested) May 12, 2022
@erikvanoosten erikvanoosten marked this pull request as draft May 12, 2022 06:59
erikvanoosten and others added 2 commits May 12, 2022 14:10
There was mostly a problem in the decoder, not in the encoder.

There are still some failing tests but those are just error string mismatches. I will work on that next.
@erikvanoosten erikvanoosten marked this pull request as ready for review May 12, 2022 12:19
@erikvanoosten
Copy link
Contributor Author

@bplommer this is ready for review now

@erikvanoosten erikvanoosten changed the title Support Option of sum types (feedback requested) Support Option of sum types May 12, 2022
@bplommer
Copy link
Member

Hi, thanks for this and sorry for the long silence! This looks good, but I'd like to try and solve it in a more generic way by making the union codec flatten nested unions in the schema. So I'm going to leave this open for now.

@erikvanoosten
Copy link
Contributor Author

Adapting the union codec was also my first attempt. I had a hard time aligning all the types. When I switched to this approach all went pretty smooth.

@bplommer
Copy link
Member

I came up with something but it’s not quite as robust because of the way the union codec uses heuristics in decoding, so I’m going to merge this as a special case. Thanks!

@bplommer bplommer merged commit bef0f4e into fd4s:master Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants