-
Notifications
You must be signed in to change notification settings - Fork 27
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
Array encode error if optional key is not presented #90
Comments
Hello thanks for the report! i verified this behavior using the following iex session. With that being said, this is the intended behavior of the API. nullable fields are not optional, so you can't omit their keys. I believe this behavior is preferable as it ensures that you have the correct data shape. Can you please explain your usecase? # Avro EX #90
```elixir
Mix.install([
{:avro_ex, "~> 2.1"}
]) Schemaprofile_schema = %{
"type" => "record",
"name" => "profile",
"fields" => [
%{"name" => "name", "type" => "string"},
%{"name" => "age", "type" => ["null", "int"]}
]
}
array_schmea = %{
"type" => "array",
"items" => [
"null",
"string",
profile_schema
]
}
final_schema = AvroEx.decode_schema!(array_schmea, strict: true) NGprofile = %{
name: "Alice"
}
example = ["1", "2", profile]
example_bin = AvroEx.encode!(final_schema, example) |> IO.inspect(label: "encode")
AvroEx.decode!(final_schema, example_bin) |> IO.inspect(label: "decode") OKprofile = %{
name: "Alice",
age: nil
}
example = ["1", "2", profile]
example_bin = AvroEx.encode!(final_schema, example) |> IO.inspect(label: "encode")
AvroEx.decode!(final_schema, example_bin) |> IO.inspect(label: "decode") |
Hi thanks for the reply! Actually, my data structure have some optional fields, and I thought My use case: |
I need to put a record into a array as an optional item.
It seems the optional key must be presented in this case.
Is this an expected behavior?
Elixir 1.8
OTP 22
:avro_ex 2.1
Schema
Usage
NG
OK
The text was updated successfully, but these errors were encountered: