2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-05-10 20:43:56 -04:00
|
|
|
# This custom serializer excludes nil values
|
|
|
|
module CustomJsonSerializer
|
2013-10-17 22:05:24 -04:00
|
|
|
extend PaperTrail::Serializers::JSON
|
2013-05-10 20:43:56 -04:00
|
|
|
|
|
|
|
def self.load(string)
|
|
|
|
parsed_value = super(string)
|
2016-02-15 20:25:11 -05:00
|
|
|
parsed_value.is_a?(Hash) ? parsed_value.reject { |k, v| k.blank? || v.blank? } : parsed_value
|
2013-05-10 20:43:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.dump(object)
|
2016-02-15 20:25:11 -05:00
|
|
|
object.is_a?(Hash) ? super(object.reject { |_k, v| v.nil? }) : super
|
2013-05-10 20:43:56 -04:00
|
|
|
end
|
2016-02-15 20:25:11 -05:00
|
|
|
end
|