hanami / db

The database layer for Hanami
MIT License
7 stars 2 forks source link

Struct serialize to json #13

Closed krzykamil closed 1 week ago

krzykamil commented 3 months ago

https://github.com/orgs/hanami/projects/6/views/1?pane=issue&itemId=70528802

This just adds a simple json conversion to struct attributes. Dumps to hash and then json.

I saw the issue description mentioned that it could also be moved to ROM or DRY gems, but I found two discussion that convinced me against it:

https://github.com/dry-rb/dry-struct/issues/166 here Nikita said "Serializing to JSON is not part of the gem and I'm against mixing concerns in general." and in the ROM thread, there was a similar mention, by Piotr https://github.com/rom-rb/rom/issues/403 "In general I would recommend encapsulating json serialization/deserialization with your own APIs, instead of referring to 3rd party gems"

So i thought its best not to nest this method too deep in those gems

cllns commented 1 month ago

@krzykamil Can you take another look at this and fix the CI failures? They seem straight-forward to fix, happy to take it over if needed.

krzykamil commented 1 month ago

@cllns my bad, completely forgot about this and the rubocop. Should be fixed now

cllns commented 2 weeks ago

Thanks @krzykamil! Do you mind changing it so that the args are passed through to the underlying .to_json? I don't think people use it much, but we might as well use the args instead of dropping them.

krzykamil commented 2 weeks ago

Thanks @krzykamil! Do you mind changing it so that the args are passed through to the underlying .to_json? I don't think people use it much, but we might as well use the args instead of dropping them.

I'll do it over the weekend, no problem

alassek commented 1 week ago

Merged as ec2942f

alassek commented 1 week ago

Thanks for the contribution, @krzykamil! I did some cleanup history rewriting on the commits so GitHub doesn't see it as a merge, but you're still listed as the author.