attr_json
attr_json copied to clipboard
consider the Rails 7.1 normalization feature
There is a new normalization feature coming in Rails 7.1. https://github.com/rails/rails/pull/43945
In attr_json 2.0, becuase of changes to sync better with ActiveRecord attribuets, i predict it should just work for attr_json attributes in an ActiveRecord::Base. (But we'll want to test it).
This could be useful for say normalizing empty strings (or all whitespace strings) to nil
, which attr_json 2.0 will then by default leave out of the json serialization. Great!
(We still might want a feature to say, specify default normalization for attributes of certain types or something?)
But... as far as I can tell, the Rails 7.1 normalization feature is not available in an ActiveModel::Model
, only in ActiveRecord models. https://github.com/rails/rails/pull/43945#issuecomment-1000918527.
- Even if it was... it might not Just Work for AttrJson, becuase we're not actually based on ActiveModel::Attributes. See #18. Although in 2.x we might be enough duck-typed that it would work anyway, depends on the implementation.... if Rails normalization were introduced for non-ActiveRecord ActiveModel ... that might be good encouragement to actually move over to ActiveModel::Attributes fully.
But we of course might want normalization in our AttrJson::Model
. Should we implement our own look-aike feature? It would not be all that hard, the basic feature is pretty straightforward and based on the Attribute APIs we're already using extensively.