maennchen / crontab

Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.
https://hex.pm/packages/crontab
MIT License
91 stars 32 forks source link

Ecto.Type: Switch embed_as to `:dump` #80

Closed mveytsman closed 3 years ago

mveytsman commented 3 years ago

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.