savonrb / nori

XML to Hash translator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nori converts String to Nori::StringWithAttributes

jedbeard opened this issue · comments

If i use savon for a soap call, i get a Hash with the response. In that hash i have Strings.
All Strings of the hash are from type Nori::StringWithAttributes instead String.
Only a result[:something].class shows that.

In my case i store the values in a Object wich i convert to yaml and this is the result:

test_id: !ruby/string:Nori::StringWithAttributes
str: '9482202'
attributes: {}

And a YAML.load(from_yaml) returns test_id = nil

@rubiii: if you need more input call me or weidenfreak ;)

cu
Jedbeard

what's this test_id thing? can you reproduce the problem or create a gist for the soap response xml?

I'm encountering this as well. It wouldn't seem like a problem, except Nori::StringWithAttributes doesn't seem to unserialize correctly from YAML.

It doesn't happen in all situations. I'll try to find a test case or something.

Here's a relevant spec (currently fails):

it "should be able to serialize and deserialize the hash to yaml losslessly" do
  xml = <<-EOT
    <product>
      <item>1</item>
    </product>
  EOT
  hash = parse(xml)
  unserialized = YAML::load(YAML::dump(hash))
  unserialized.should == hash
end

This issue also exists when parsing an XML file. I created a Gist to demonstrate the problem. https://gist.github.com/3630294

This turned out not to be a bug in nori, and you can find the solution in the discussion on #24.

I think this issue can probably be closed.

yep. thanks!

So yeah, this is an old issue, but I think it's coming up again in the latest version 2.5.1. The YAML.dump below gives me the same Nori::StringWithAttributes stuff mentioned in the first post.

      result = @client.call command_name,
                            cookies: @auth_cookies,
                            message: { :token => @token }.merge(message)

      YAML.dump result.hash[:envelope][:body][response_key][result_key]

@gnilrets would you mind opening a new issue for this behavior you described? If possible, could you provide a stand alone example? It's really hard to glean enough context from the snippet you posted to determine what's going on and to know how to start investigating.