Replies: 2 comments 4 replies
-
@jwoertink That last thought on I know we're not looking to add third party libs as dependencies, but I wonder if there are any good nuggets in that implementation? |
Beta Was this translation helpful? Give feedback.
-
Don't forget about reading from the database too. I do wish Crystal had something better for this. Part of the reason that things are so complicated is that the crystal-pg shard is built with json::any in mind rather than json::serializable. As I recall, it would be a significant breaking change to alter this because it's not possible to opt-in to the behavior. I like the idea of using something like sija's any_hash, but I also like the idea of implementing something which converts (both read- and write-time) between the json::any and whatever serializable object is being stuffed into the column. |
Beta Was this translation helpful? Give feedback.
-
If you have any
jsonb
columns on your models, then you'll have to deal withJSON::Any
which can be sort of a pain. Let's say that you are updating this column, and the structure is saved in a Serializer.You have a few options here..
There's also a few other issues along with
JSON::Any
doesn't allow for UUID instances, and probably quite a few others. The error message you get is also less than optimal:🤔 so I guess
UUID
, andNamedTuple
aren't araw : Type
butString
is...Lastly, just the general setup of an empty JSON::Any object gets a bit tedious.
With all this information, should Lucky handle this structure internally somehow? Like providing some wrapper? Maybe monkeypatch to include a
.to_json_any
type method? Or is this all complex enough to ask the Crystal language itself for something better? Or do we just say that this is the downside to using json, but it provides the most type-safe handling?Beta Was this translation helpful? Give feedback.
All reactions