This project is archived and is in readonly mode.

#1487 ✓invalid
timuckun

from_xml and from_json don't work

Reported by timuckun | November 27th, 2008 @ 09:51 PM | in 2.x

Here is a transcript from a console session

u = User.find(1) => #itdepartment@panztel.com", crypted_password: "81d8c8a916ddf51de06a3cef5a50498698183273", salt: "b57457ea9c805ef82ed34349eeb0dd0f8fe0f848", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 4, address_id: nil>

xml = u.to_xml => "<?xml version="1.0" encoding="UTF-8"?>\n\n <activated-at type="datetime">2008-11-19T22:12:07Z</activated-at>\n <activation-code>a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805</activation-code>\n <address-id type="integer" nil="true"></address-id>\n <company-id type="integer">1</company-id>\n <crypted-password>81d8c8a916ddf51de06a3cef5a50498698183273</crypted-password>\n itdepartment@panztel.com\n true\n 1\n <lock-version type="integer">4</lock-version>\n admin\n <password-reset-code nil="true"></password-reset-code>\n <remember-token nil="true"></remember-token>\n <remember-token-expires-at type="datetime" nil="true"></remember-token-expires-at>\n b57457ea9c805ef82ed34349eeb0dd0f8fe0f848\n UTC\n\n"

Change the time zone to ABC instead of UTC

xml = "<?xml version="1.0" encoding="UTF-8"?>\n\n <activated-at type="datetime">2008-11-19T22:12:07Z</activated-at>\n <activation-code>a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805</activation-code>\n <address-id type="integer" nil="true"></address-id>\n <company-id type="integer">1</company-id>\n <crypted-password>81d8c8a916ddf51de06a3cef5a50498698183273</crypted-password>\n itdepartment@panztel.com\n true\n 1\n lock-version type="integer">4</lock-version>\n admin\n <password-reset-code nil="true"></password-reset-code>\n <remember-token nil="true"></remember-token>\n <remember-token-expires-at type="datetime" nil="true"></remember-token-expires-at>\n b57457ea9c805ef82ed34349eeb0dd0f8fe0f848\n ABC\n\n" => "<?xml version="1.0" encoding="UTF-8"?>\n\n <activated-at type="datetime">2008-11-19T22:12:07Z</activated-at>\n <activation-code>a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805</activation-code>\n <address-id type="integer" nil="true"></address-id>\n <company-id type="integer">1</company-id>\n <crypted-password>81d8c8a916ddf51de06a3cef5a50498698183273</crypted-password>\n itdepartment@panztel.com\n true\n 1\n lock-version type="integer">4</lock-version>\n admin\n <password-reset-code nil="true"></password-reset-code>\n <remember-token nil="true"></remember-token>\n <remember-token-expires-at type="datetime" nil="true"></remember-token-expires-at>\n b57457ea9c805ef82ed34349eeb0dd0f8fe0f848\n ABC\n\n"

u.from_xml(xml) REXML::ParseException: #<REXML::ParseException: Missing end tag for 'user' (got "lock-version") Line: Position: Last 80 unconsumed characters: admin <password-reset-code nil="true"></password-reset-code> > /usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:330:in pull' /usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:22:inparse' /usr/lib/ruby/1.8/rexml/document.rb:228:in build' /usr/lib/ruby/1.8/rexml/document.rb:43:ininitialize' /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb:952:in new' /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb:952:inparse' /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/conversions.rb:12:in xml_in_string' /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/conversions.rb:23:inxml_in_string' /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/conversions.rb:171:in from_xml' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/serializers/xml_serializer.rb:159:infrom_xml' (irb):128:in irb_binding' /usr/lib/ruby/1.8/irb/workspace.rb:52:inirb_binding' :0 ... Missing end tag for 'user' (got "lock-version") Line: Position: Last 80 unconsumed characters: admin <password-reset-code nil="true"></password-reset-code> Line: Position: Last 80 unconsumed characters: admin <password-reset-code nil="true"></password-reset-code>

from /usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:92:in `parse'
from /usr/lib/ruby/1.8/rexml/document.rb:228:in `build'
from /usr/lib/ruby/1.8/rexml/document.rb:43:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb:952:in `new'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb:952:in `parse'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/conversions.rb:12:in `xml_in_string'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/conversions.rb:23:in `xml_in_string'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/hash/conversions.rb:171:in `from_xml'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/serializers/xml_serializer.rb:159:in `from_xml'
from (irb):128
from :0

Let's try with json.

json = u.to_json => "{"user": {"salt": "b57457ea9c805ef82ed34349eeb0dd0f8fe0f848", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "81d8c8a916ddf51de06a3cef5a50498698183273", "password_reset_code": null, "lock_version": 4, "activation_code": "a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805", "timezone": "UTC", "id": 1, "enabled": true, "address_id": null, "remember_token": null, "company_id": 1, "login": "admin", "email": "itdepartment@panztel.com"}}"

Change the timezone again.

json = "{"user": {"salt": "b57457ea9c805ef82ed34349eeb0dd0f8fe0f848", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "81d8c8a916ddf51de06a3cef5a50498698183273", "password_reset_code": null, "lock_version": 4, "activation_code": "a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805", "timezone": "ABC", "id": 1, "enabled": true, "address_id": null, "remember_token": null, "company_id": 1, "login": "admin", "email": "itdepartment@panzel.com"}}" => "{"user": {"salt": "b57457ea9c805ef82ed34349eeb0dd0f8fe0f848", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "81d8c8a916ddf51de06a3cef5a50498698183273", "password_reset_code": null, "lock_version": 4, "activation_code": "a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805", "timezone": "ABC", "id": 1, "enabled": true, "address_id": null, "remember_token": null, "company_id": 1, "login": "admin", "email": "itdepartment@panzel.com"}}"

Apply to the model

u.from_json(json) => #itdepartment@panztel.com", crypted_password: "81d8c8a916ddf51de06a3cef5a50498698183273", salt: "b57457ea9c805ef82ed34349eeb0dd0f8fe0f848", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 4, address_id: nil>

Note the timezone has not changed. It's still UTC.

u.save => true u => #itdepartment@panztel.com", crypted_password: "81d8c8a916ddf51de06a3cef5a50498698183273", salt: "b57457ea9c805ef82ed34349eeb0dd0f8fe0f848", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "a7ec9376c35dd28ae6f6ab0d74f5a5df773b6805", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 5, address_id: nil>

Comments and changes to this ticket

  • timuckun

    timuckun November 27th, 2008 @ 10:14 PM

    Looks like the errors due to cut and paste. Still doesn't update the record though.

    u = User.find(3)

    => #tm_user@panztel.com", crypted_password: "b695db100847aa269fb477443a289d875cf2e001", salt: "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "bab0c2bc67d43b6871005559b114b9b62b7b70bb", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 4, address_id: nil>

    u.to_xml

    => "<?xml version="1.0" encoding="UTF-8"?>\n\n <activated-at type="datetime">2008-11-19T22:12:07Z</activated-at>\n <activation-code>bab0c2bc67d43b6871005559b114b9b62b7b70bb</activation-code>\n <address-id type="integer" nil="true"></address-id>\n <company-id type="integer">3</company-id>\n <crypted-password>b695db100847aa269fb477443a289d875cf2e001</crypted-password>\n tm_user@panztel.com\n true\n 3\n <lock-version type="integer">4</lock-version>\n tm_user\n <password-reset-code nil="true"></password-reset-code>\n <remember-token nil="true"></remember-token>\n <remember-token-expires-at type="datetime" nil="true"></remember-token-expires-at>\n 1e3a4ba1ccb233c2bbd92c3bdbb917307523671b\n UTC\n\n"

    Change the XML. Change the timezone from UTC to ABC

    a = "<?xml version="1.0" encoding="UTF-8"?>\n\n <activated-at type="datetime">2008-11-19T22:12:07Z</activated-at>\n <activation-code>bab0c2bc67d43b6871005559b114b9b62b7b70bb</activation-code>\n <address-id type="integer" nil="true"></address-id>\n <company-id type="integer">3</company-id>\n <crypted-password>b695db100847aa269fb477443a289d875cf2e001</crypted-password>\n tm_user@panztel.com\n true\n 3\n <lock-version type="integer">4</lock-version>\n tm_user\n <password-reset-code nil="true"></password-reset-code>\n <remember-token nil="true"></remember-token>\n <remember-token-expires-at type="datetime" nil="true"></remember-token-expires-at>\n 1e3a4ba1ccb233c2bbd92c3bdbb917307523671b\n ABC\n\n"

    Apply it back to the record.

    u.from_xml(a)

    u.from_xml(a)

    => #tm_user@panztel.com", crypted_password: "b695db100847aa269fb477443a289d875cf2e001", salt: "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "bab0c2bc67d43b6871005559b114b9b62b7b70bb", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 4, address_id: nil>

    Mmmmm. timezone is still UTC.

    Let's save it.

    u.save => true u => #tm_user@panztel.com", crypted_password: "b695db100847aa269fb477443a289d875cf2e001", salt: "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "bab0c2bc67d43b6871005559b114b9b62b7b70bb", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 5, address_id: nil>

    Looks like the time zone never got changed.

    Let's try with json

    u.to_json => "{"user": {"salt": "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "b695db100847aa269fb477443a289d875cf2e001", "password_reset_code": null, "lock_version": 5, "activation_code": "bab0c2bc67d43b6871005559b114b9b62b7b70bb", "timezone": "UTC", "id": 3, "enabled": true, "address_id": null, "remember_token": null, "company_id": 3, "login": "tm_user", "email": "tm_user@panztel.com"}}" j = "{"user": {"salt": "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "b695db100847aa269fb477443a289d875cf2e001", "password_reset_code": null, "lock_version": 5, "activation_code": "bab0c2bc67d43b6871005559b114b9b62b7b70bb", "timezone": "ABC", "id": 3, "enabled": true, "address_id": null, "remember_token": null, "company_id": 3, "login": "tm_user", "email": "tm_user@panztelcom"}}" => "{"user": {"salt": "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "b695db100847aa269fb477443a289d875cf2e001", "password_reset_code": null, "lock_version": 5, "activation_code": "bab0c2bc67d43b6871005559b114b9b62b7b70bb", "timezone": "ABC", "id": 3, "enabled": true, "address_id": null, "remember_token": null, "company_id": 3, "login": "tm_user", "email": "tm_user@panztelcom"}}" j => "{"user": {"salt": "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", "activated_at": "2008-11-19T22:12:07Z", "remember_token_expires_at": null, "crypted_password": "b695db100847aa269fb477443a289d875cf2e001", "password_reset_code": null, "lock_version": 5, "activation_code": "bab0c2bc67d43b6871005559b114b9b62b7b70bb", "timezone": "ABC", "id": 3, "enabled": true, "address_id": null, "remember_token": null, "company_id": 3, "login": "tm_user", "email": "tm_user@panztelcom"}}" u.from_json(j) => #tm_user@panztel.com", crypted_password: "b695db100847aa269fb477443a289d875cf2e001", salt: "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "bab0c2bc67d43b6871005559b114b9b62b7b70bb", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 5, address_id: nil> u.save => true u => #tm_user@panztel.com", crypted_password: "b695db100847aa269fb477443a289d875cf2e001", salt: "1e3a4ba1ccb233c2bbd92c3bdbb917307523671b", timezone: "UTC", remember_token: nil, remember_token_expires_at: nil, activation_code: "bab0c2bc67d43b6871005559b114b9b62b7b70bb", activated_at: "2008-11-19 22:12:07", password_reset_code: nil, enabled: true, created_at: "2008-11-19 22:12:07", updated_at: "2008-11-19 22:12:07", lock_version: 6, address_id: nil>

    Exact same story.

  • Frederick Cheung

    Frederick Cheung December 8th, 2008 @ 03:03 PM

    Looks like lighthouse has somewhat mangled what you wrote.

    Can you reduce this to a minimal example, where you - take a model - dump the xml - change the xml using gsub (to rule out cut & paste etc...) - load it back in

    along with the simplest possible class and the simplest possible schema ?

  • Geoff Buesing

    Geoff Buesing February 8th, 2009 @ 06:18 PM

    • State changed from “new” to “stale”

    If this is still an issue, please reopen with 1. a patch, either with a fix, or at least a failing test case, or 2 if you can't generate a patch, the simplest possible example that illustrates this issue, as Frederick suggests.

    Please also use Lighthouse's built-in syntax highlighting (see "formatting help" link above "add a comment" text field), it will help others read through your code.

  • CancelProfileIsBroken
  • Mike Breen

    Mike Breen August 9th, 2009 @ 06:10 PM

    I cannot reproduce this on 2-3-stable.

  • Rizwan Reza

    Rizwan Reza August 9th, 2009 @ 06:25 PM

    not reproducible

    -1 I followed the steps. May be because my application doesn't show UTC explicitly... I tried changing times but it's not reproducing. It is working as expected for me. May be timuckun should have a demo app at github for this.

  • Derander

    Derander August 9th, 2009 @ 08:21 PM

    Unable to reproduce.

    -1

    I followed the steps as well. I'm not ruling out copy paste error on my end, but I was unable to see the behavior described.

  • CancelProfileIsBroken

    CancelProfileIsBroken August 9th, 2009 @ 11:01 PM

    • Tag cleared.
    • State changed from “stale” to “invalid”

    No repro, no more reports of the same behavior, marking invalid.

  • Vimax

    Vimax February 1st, 2011 @ 04:46 PM

    This is the thing I'm looking for over the net. Finally I found male enhancement products on the market today. But which of them actually work? With a lot of brands available, Vigrx Plus is the safer to use the mark which is purely natural. Other products is Vimax.

  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages