1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/test/custom_json_serializer.rb

13 lines
378 B
Ruby
Raw Normal View History

# This custom serializer excludes nil values
module CustomJsonSerializer
extend PaperTrail::Serializers::JSON
def self.load(string)
parsed_value = super(string)
parsed_value.is_a?(Hash) ? parsed_value.reject { |k,v| k.blank? || v.blank? } : parsed_value
end
def self.dump(object)
object.is_a?(Hash) ? super(object.reject { |k,v| v.nil? }) : super
end
end