lib/rest_model/serialization/integer.rb in rest_model-0.1.17 vs lib/rest_model/serialization/integer.rb in rest_model-0.1.18

- old
+ new

@@ -1,17 +1,24 @@ class RestModel module Serialization class Integer def self.serialize(value) - Integer(value) + case value + when String + if value =~ /^\d+$/ + value.to_i + else + raise + end + else + Integer(value) + end rescue raise SerializationError, "value '#{value}' is not an integer" end def self.desserialize(value) - Integer(value) - rescue - raise SerializationError, "value '#{value}' is not an integer" + serialize(value) end end end end