Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
support serializing managed and data objects to anyType fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Lane committed Mar 20, 2012
1 parent ae36316 commit ad5a17a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rbvmomi/connection.rb
Expand Up @@ -132,10 +132,10 @@ def obj2xml xml, name, type, is_array, o, attrs={}
end
end
when BasicTypes::ManagedObject
fail "expected #{expected.wsdl_name}, got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class
fail "expected #{expected.wsdl_name}, got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
xml.tag! name, o._ref, :type => o.class.wsdl_name
when BasicTypes::DataObject
fail "expected #{expected.wsdl_name}, got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class
fail "expected #{expected.wsdl_name}, got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
xml.tag! name, attrs.merge("xsi:type" => o.class.wsdl_name) do
o.class.full_props_desc.each do |desc|
if o.props.member? desc['name'].to_sym
Expand Down
16 changes: 16 additions & 0 deletions test/test_serialization.rb
Expand Up @@ -292,4 +292,20 @@ def test_time
<root>2011-11-16T13:36:08-08:00</root>
EOS
end

# TODO test all types
def test_any_type
obj = 1
check <<-EOS, obj, 'xsd:anyType', false
<root xsi:type="xsd:long">1</root>
EOS

obj = VIM::HostAccountSpec(:id => 'root', :password => 'foo')
check <<-EOS, obj, 'xsd:anyType', false
<root xsi:type="HostAccountSpec">
<id>root</id>
<password>foo</password>
</root>
EOS
end
end

0 comments on commit ad5a17a

Please sign in to comment.