[yast-commit] <rest-service> jr-basemodel : serialize properly types
ref: refs/heads/jr-basemodel commit 059b914354a07c7391bedf5e15ed48066c87d061 Author: Josef Reidinger <jreidinger@suse.cz> Date: Fri Dec 11 12:57:36 2009 +0100 serialize properly types --- .../lib/base_model/serializers/xml_serializer.rb | 20 +++++++++++++++++++- webservice/test/unit/base_model_test.rb | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/webservice/lib/base_model/serializers/xml_serializer.rb b/webservice/lib/base_model/serializers/xml_serializer.rb index 8522710..de98e56 100644 --- a/webservice/lib/base_model/serializers/xml_serializer.rb +++ b/webservice/lib/base_model/serializers/xml_serializer.rb @@ -40,9 +40,27 @@ module BaseModel end end else - builder.tag!(name,value.to_s) + type = XML_TYPE_NAMES[value.class.to_s] + opts = {} + opts[:type] = type if type + builder.tag!(name,value.to_s,opts) end end + + XML_TYPE_NAMES = { #type conversion + "Symbol" => "symbol", + "Fixnum" => "integer", + "Bignum" => "integer", + "BigDecimal" => "decimal", + "Float" => "float", + "TrueClass" => "boolean", + "FalseClass" => "boolean", + "Date" => "date", + "DateTime" => "datetime", + "Time" => "datetime", + "ActiveSupport::TimeWithZone" => "datetime" + } unless defined?(XML_TYPE_NAMES) + end end end diff --git a/webservice/test/unit/base_model_test.rb b/webservice/test/unit/base_model_test.rb index 34f9466..7a2fffd 100644 --- a/webservice/test/unit/base_model_test.rb +++ b/webservice/test/unit/base_model_test.rb @@ -56,7 +56,8 @@ MASS_DATA = { :arg1 => "last", :arg2 => "5", :callback_used => false } COMPLEX_DATA = { "test" => [ "a","b"], #serializers doesn't differ symbol from string and always sue string - "test2" => [ "5","6"], #number after serializing is converted to string + "test2" => [ 5,6], #number test + "test4" => [ true,false], #number boolean "test3" => { "a" => "b","c"=> "d" }, #number after serializing is converted to string "test_escapes" => "<arg>/&\\test", "test_hash" => [{"a"=>"a"},{"b"=>"b"}] -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Josef Reidinger