yosiat / panko_serializer

High Performance JSON Serialization for ActiveRecord & Ruby Objects
https://panko.dev
MIT License
592 stars 36 forks source link

Allow to dynamically skip a field by returning SKIP #92

Closed casperisfine closed 3 years ago

casperisfine commented 3 years ago

Context

I'm trying to convert one of our app that uses AMS 0.9 (https://github.com/Shopify/shipit-engine/pull/1139), but one missing feature the the possibility of skipping an attribute.

I've read https://github.com/panko-serializer/panko_serializer/issues/16 and I understand the performance concern, however I think it can be done efficiently.

This PR

It define a special value Panko::Serializer::SKIP, if a serializer field returns it, the field is not serialized. The performance overhead should be totally negligible.

silva96 commented 1 year ago

It would be great if there exists some kind of documentation or reference of this feature. I discovered it by luck.