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

Ecto.Type: Switch embed_as to :dump #80

Merged
merged 1 commit into from
Aug 19, 2021
Merged

Conversation

mveytsman
Copy link
Contributor

When using the Ecto typ inside of an embedded schema, we get the following error:

protocol Jason.Encoder not implemented for ~e[0 12 * * 1 *] of type Crontab.CronExpression (a struct), Jason.Encoder protocol must always be explicitly implemented.

This is because by default the type will be embedded as a JSON dump of it's struct (see https://hexdocs.pm/ecto/Ecto.Type.html#c:embed_as/1)

Switching to :dump means that when embedding this type in a embedded schema we still call the dump callback, and the error goes away.

When using the Ecto typ inside of an embedded schema, we get the following error:

```
protocol Jason.Encoder not implemented for ~e[0 12 * * 1 *] of type Crontab.CronExpression (a struct), Jason.Encoder protocol must always be explicitly implemented.
```

This is because by default the type will be embedded as a JSON dump of it's struct (see https://hexdocs.pm/ecto/Ecto.Type.html#c:embed_as/1)

Switching to `:dump` means that when embedding this type in a embedded schema we still call the `dump` callback, and the error goes away.
@maennchen maennchen merged commit c572bd0 into maennchen:master Aug 19, 2021
@mveytsman mveytsman deleted the patch-1 branch August 24, 2021 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants