purplesquirrel
Configure Jason/Postgrex to decode maps with keys as atom by default
I’m using Jason to store some maps in Postgresql. I much prefer the atom syntax for defining and accessing keys and I want to avoid half-string half-atom mixed style maps if possible.
I can see that Jason.decode has an option keys: :atoms, but I can’t for the life of me find anywhere to configure it as a default option with Phoenix/etc. I’ve tried looking around Jason, Ecto and Postgrex’s source.
I’m aware that atoms aren’t garbage collected but I’m not taking key names from users so I’m not worried about uncontrolled memory usage.
Marked As Solved
hauleth
If you know beforehand what will that map contain then you can use embeds_one/embeds_many with embedded_schema instead.
Also Liked
LostKobrakai
You could always implement your own Ecto.Type based on the map field. I doubt ecto itself will ever allow you to set that.
Edit: A Postgrex.Type directly might work as well.
LostKobrakai
A potential DOS attack vector is probably reason enough to not allow it.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









