-
Notifications
You must be signed in to change notification settings - Fork 35
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
Unable to set nonempty default for optional field #518
Comments
EDIT: the below is the original post, but a warning to those who find it hereafter that this did not work. A coworker discovered a workaround which looks like it will suffice for our case: that is, everywhere we are using that enumeration, we are using the same default. Setting the default on the enumeration instead of on the field, works. So we can probably move ahead; but the above still looks like a bug to me. |
Well, I hope. I have not fully validated this hope yet. |
Got hit with this issue as well, and discovered an annoyance: https://avro.apache.org/docs/1.8.1/spec.html#Unions
So the default value for an |
@soujiro32167 unless you have the null second, which is the way that Avro4s has it IIRC. |
Right, whatever the first is, is the one you can default to |
Oh, Avro4s seems to change the way its option codecs work based on the default, sometimes putting |
This did not work. Looks like this will, however: private implicit lazy val optionAllowingDefaultSome
: Codec[Option[Int]] =
Codec.union(builder =>
builder[Some[Int]] <+>
builder[None.type]
) A locally-scoped monomorphic implicit that puts the |
I am working on converting some contracts from using Avro4s to Vulcan. Because they are existing contracts I am constrained in what I can do---I am attempting to produce precisely equivalent Avro before and after.
I've hit a case that's giving me trouble. The following is a MWE.
This results in a
Foo.codec.schema
which is aLeft
containingIn my example, I was using an enum, not an integer, and got the same behavior. I noticed that
Some(None)
works as a default, but this does not match my existing contracts.The text was updated successfully, but these errors were encountered: