Ticket #17 (closed defect: fixed)

Opened 2 years ago

Last modified 23 months ago

Make null fields in Rails flavored XML deserialize

Reported by: jared Owned by:
Priority: blocker Milestone: 0.3
Version: Keywords:
Cc:

Description (last modified by jared) (diff)

Rails by default emits improper (well, maybe not improper, but at least slimy) XML. The ActiveResource modules works similarly to ActiveRecord; that is, they both autodiscover what fields are available. ActiveRecord does this by looking at the table (ie the metadata). ActiveResource does this by looking at the data (ie the XML), because there is no metadata exposed by the service.

In order to make sure that the data always contains all of the fields, Rails serializes null fields like this:

<person>
  <id type="integer">2</id>
  <name nil="true"/>
</person>

instead of like this:

<person>
  <id type="integer">2</id>
</person>

This little trick ensures that ActiveResource can discover that the name fields exists. When xstream deserializes the rails flavored XML, it rightly says there is a name field with an empty string value. Which isn't what the Rails service was trying to say.

To work around this, I create the RailsConverterRegistry class, which wraps all of the xstream converters so it can check for the nil attribute. This essentially destroys xstream's attribute support, good thing we don't need it. However, this converter registry doesn't seem to be working right, because when you use it, xstream can't locate your class to deserialize into, you get a "No converter specified for class ...." error.

There is a test written for this in TestResourceFactory#testDeserializeOne2()

Change History

comment:1 Changed 2 years ago by jared

Tests created in r48

comment:2 Changed 2 years ago by jared

  • Priority changed from major to blocker
  • Milestone changed from backlog to 0.3

comment:3 Changed 2 years ago by jared

  • Description modified (diff)

comment:4 Changed 23 months ago by jared

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in r81. Created the RailsConverterLookup? class which wraps all incoming Converters so we can make each of them check for the nil attribute in the XML.

Note: See TracTickets for help on using tickets.