[yast-commit] <rest-service> master : serialize only values which is not nil (to determine difference between empty value and nil value)
ref: refs/heads/master commit d7761e7f9931cba8267c3f77406337ec6a5d7c86 Author: Josef Reidinger <jreidinger@suse.cz> Date: Wed Dec 16 15:05:47 2009 +0100 serialize only values which is not nil (to determine difference between empty value and nil value) --- .../lib/base_model/serializers/json_serializer.rb | 3 ++- .../lib/base_model/serializers/xml_serializer.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/webservice/lib/base_model/serializers/json_serializer.rb b/webservice/lib/base_model/serializers/json_serializer.rb index ad984f0..e41fa0a 100644 --- a/webservice/lib/base_model/serializers/json_serializer.rb +++ b/webservice/lib/base_model/serializers/json_serializer.rb @@ -17,7 +17,8 @@ private def as_json(options={}) hash = {} Serializer.new(self,options).attributes.each do |attr| - hash[attr.to_s[1..-1]] = instance_variable_get(attr) + val = instance_variable_get(attr) + hash[attr.to_s[1..-1]] = val unless val.nil? #remove nil values end hash = { self.class.model_name.singular => hash } hash diff --git a/webservice/lib/base_model/serializers/xml_serializer.rb b/webservice/lib/base_model/serializers/xml_serializer.rb index e8289a6..e3317a2 100644 --- a/webservice/lib/base_model/serializers/xml_serializer.rb +++ b/webservice/lib/base_model/serializers/xml_serializer.rb @@ -24,7 +24,7 @@ module BaseModel @attributes.each do |attr| value = @model.instance_variable_get(attr) name = attr.to_s[1..-1] - serialize_value(name,value,builder) + serialize_value(name,value,builder) unless value.nil? end } end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Josef Reidinger