<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SmartLogic Solutions Blog &#187; Serialization</title>
	<atom:link href="http://blog.smartlogicsolutions.com/category/serialization/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>I Won the AIR Cook-off</title>
		<link>http://blog.smartlogicsolutions.com/2008/10/29/i-won-the-air-cook-off/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/10/29/i-won-the-air-cook-off/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 02:26:18 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[cookbook]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=354</guid>
		<description><![CDATA[I was waiting to post this until the results were announced which they were today. O&#8217;Reilly just posted the winners of the Adobe AIR Cook-off and I&#8217;m pleased to say I won the grand prize! My recipe was Migrating Serialization Changes in AIR. Thanks to anyone who voted for it. I have a follow-up recipe [...]]]></description>
			<content:encoded><![CDATA[<p>I was waiting to post this until the results were announced which they were today.  O&#8217;Reilly just <a href="http://www.insideria.com/2008/10/oreilly-contest-winners-for-ad.html">posted the winners</a> of the <a href="http://www.adobe.com/devnet/logged_in/mkoch_aircookoff.html">Adobe AIR Cook-off</a> and I&#8217;m pleased to say I won the grand prize!</p>
<p>My recipe was <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showDetails&#038;postId=10743&#038;productId=4&#038;loc=en_US">Migrating Serialization Changes in AIR</a>.  Thanks to anyone who voted for it.</p>
<p>I have a follow-up recipe I haven&#8217;t gotten to write up yet, but I&#8217;ll try to get it up in the next week.  It will provide a solution to add the marker which is required for this serialization to work to the front of your structures if you already have files being serialized in an existing AIR application and you want to start taking advantage of this migration technique.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/" rel="bookmark" class="crp_title">Migrating Serialization Changes Within an AIR Application</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/17/migrairable-library-added-to-google-code/" rel="bookmark" class="crp_title">MigrAIRable Library Added to Google Code</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/03/31/air-linux-adobe-alpha-flexbuilder/" rel="bookmark" class="crp_title">Adobe AIR Alpha Released on Linux</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/02/25/flex-air-released-adobe/" rel="bookmark" class="crp_title">AIR 1.0 and Flex 3 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2007/08/21/adobe-onair-bus-tour-baltimore/" rel="bookmark" class="crp_title">Adobe onAIR Bus Tour: Baltimore</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/10/29/i-won-the-air-cook-off/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making WillPaginate and Rails to_xml play nice with ActiveResource</title>
		<link>http://blog.smartlogicsolutions.com/2008/10/10/making-willpaginate-and-rails-to_xml-play-nice-with-activeresource/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/10/10/making-willpaginate-and-rails-to_xml-play-nice-with-activeresource/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 19:48:57 +0000</pubDate>
		<dc:creator>Scott Davis</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scott Davis]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Rails Will_Paginate to_xml ActiveResource]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=305</guid>
		<description><![CDATA[We are currently working on a project that involves Flex and active resource + will_paginate and we needed to be able to paginate the xml transactions easily. Unfortunately, will_paginate and to_xml don&#8217;t play nicely when it comes to adding the current_page, total_pages, and page attributes to the xml. After many failed attempts I went looking around github [...]]]></description>
			<content:encoded><![CDATA[<p>We are currently working on a project that involves Flex and active resource + will_paginate and we needed to be able to paginate the xml transactions easily. Unfortunately, will_paginate and to_xml don&#8217;t play nicely when it comes to adding the current_page, total_pages, and page attributes to the xml. After many failed attempts I went looking around <a href="http://github.com">github</a> and found in a few <a href="http://github.com/agile/will_paginate/tree/master">forks</a> of <a href="http://github.com/mislav/will_paginate/tree/master/">will paginate</a> that some people had solved this problem but, I didn&#8217;t want to install another version of the gem to risk breaking other apps on the server so I did it the rails way!</p>
<p>I started by creating a module that opens up the will_paginate <a href="http://github.com/mislav/will_paginate/tree/master/lib/will_paginate/collection.rb">collection</a> class and includes ActiveResource and alias method chain the to_xml method to include these values. Example code below.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#enviroment.rb</span>
...
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'to_xml_extensions'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#lib/to_xml_extensions.rb</span>
<span style="color:#9966CC; font-weight:bold;">module</span> WillPaginateHelpers
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC0066; font-weight:bold;">Array</span>::Conversions
  <span style="color:#9966CC; font-weight:bold;">def</span> to_xml_with_collection_type<span style="color:#006600; font-weight:bold;">&#40;</span>options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        serializeable_collection.<span style="color:#9900CC;">to_xml_without_collection_type</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>xml<span style="color:#006600; font-weight:bold;">|</span>
          xml.<span style="color:#9900CC;">tag</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:current_page</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC00FF; font-weight:bold;">Hash</span>::<span style="color:#6666ff; font-weight:bold;">Conversions::XML_TYPE_NAMES</span><span style="color:#006600; font-weight:bold;">&#91;</span>current_page.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, current_page<span style="color:#006600; font-weight:bold;">&#41;</span>
          xml.<span style="color:#9900CC;">tag</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:per_page</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC00FF; font-weight:bold;">Hash</span>::<span style="color:#6666ff; font-weight:bold;">Conversions::XML_TYPE_NAMES</span><span style="color:#006600; font-weight:bold;">&#91;</span>per_page.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, per_page<span style="color:#006600; font-weight:bold;">&#41;</span>
          xml.<span style="color:#9900CC;">tag</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:total_entries</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC00FF; font-weight:bold;">Hash</span>::<span style="color:#6666ff; font-weight:bold;">Conversions::XML_TYPE_NAMES</span><span style="color:#006600; font-weight:bold;">&#91;</span>total_entries.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, total_entries<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>type=<span style="color:#996600;">&quot;array&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>type=<span style="color:#996600;">&quot;collection&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      alias_method_chain <span style="color:#ff3333; font-weight:bold;">:to_xml</span>, <span style="color:#ff3333; font-weight:bold;">:collection_type</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> serializeable_collection <span style="color:#008000; font-style:italic;">#:nodoc:</span>
        <span style="color:#008000; font-style:italic;"># Ugly hack because to_xml will not yield the XML Builder object when empty?</span>
        empty? ? returning<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">clone</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> c.<span style="color:#9900CC;">instance_eval</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#9966CC; font-weight:bold;">def</span> empty?; <span style="color:#0000FF; font-weight:bold;">false</span>; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> : <span style="color:#0000FF; font-weight:bold;">self</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">WillPaginate::Collection</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span>, WillPaginateHelpers<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This now gives me the proper xml when I call to_xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;time-cards</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;collection&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;current_page</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/current_page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;per_page</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>25<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/per_page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;total_entries</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>108<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/total_entries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;time_card<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;approved</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/approved<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;billable</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/billable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;created_at</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;datetime&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2008-10-10T14:04:13-04:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/created_at<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;date</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;datetime&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2008-10-10T14:04:13-04:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;has_been_billed</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/has_been_billed<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;has_been_paid</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/has_been_paid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hours</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;float&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hours<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>98<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;is_overtime</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/is_overtime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;task_id</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/task_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;updated_at</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;datetime&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2008-10-10T14:04:13-04:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/updated_at<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user_id</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/time_card<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  ...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/timecards<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/10/28/faking-a-will-paginate-collection-on-an-active-resource-model/" rel="bookmark" class="crp_title">Faking a Will Paginate Collection on an Active Resource model</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/13/ruby-on-rails-polymorphic-association-benchmarks/" rel="bookmark" class="crp_title">Ruby on Rails Polymorphic Association Benchmarks</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/01/microsoft-webdav-opens-document-as-read-only-when-using-railsdav/" rel="bookmark" class="crp_title">Microsoft WebDav opens document as Read-Only when using RailsDav</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/09/10/using-activerecords-to_xml-to-produce-custom-xml-including-deep-level-associations/" rel="bookmark" class="crp_title">Using ActiveRecord&#8217;s to_xml to produce custom xml including deep level associations</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/03/error-in-will_paginate-gem-running-rails-210/" rel="bookmark" class="crp_title">Error in will_paginate gem running Rails 2.1.0</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/10/10/making-willpaginate-and-rails-to_xml-play-nice-with-activeresource/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Migrating Serialization Changes Within an AIR Application</title>
		<link>http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 06:50:07 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[Migration]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=255</guid>
		<description><![CDATA[I just submitted my entry to the AIR Cookbook for the AIR Cookbook Cook-off. It solves the problem of having your AIR application store an IExternalizable class on disk but then later adding more fields to that class. How would you read the old version of the class without encountering a runtime error if you [...]]]></description>
			<content:encoded><![CDATA[<p>I just submitted <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&#038;postid=10743&#038;loc=en_US&#038;productid=4">my entry</a> to the <a href="http://www.adobe.com/go/air_cookbook">AIR Cookbook</a> for the <a href="http://www.adobe.com/devnet/logged_in/mkoch_aircookoff.html">AIR Cookbook Cook-off</a>.</p>
<p>It solves the problem of having your AIR application store an <code>IExternalizable</code> class on disk but then later adding more fields to that class.  How would you read the old version of the class without encountering a runtime error if you tried to read the new field that wasn&#8217;t present in the older serialization?</p>
<p>Go <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&#038;postid=10743&#038;loc=en_US&#038;productid=4">check it out</a> the cookbook entry to find out how to do this and please rate the article!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/10/29/i-won-the-air-cook-off/" rel="bookmark" class="crp_title">I Won the AIR Cook-off</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/17/migrairable-library-added-to-google-code/" rel="bookmark" class="crp_title">MigrAIRable Library Added to Google Code</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/02/25/flex-air-released-adobe/" rel="bookmark" class="crp_title">AIR 1.0 and Flex 3 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/03/31/air-linux-adobe-alpha-flexbuilder/" rel="bookmark" class="crp_title">Adobe AIR Alpha Released on Linux</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/" rel="bookmark" class="crp_title">Serialization Error/Bug When Using a ByteArray and readObject in an IExternalizable Class?</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Serialization Error/Bug When Using a ByteArray and readObject in an IExternalizable Class?</title>
		<link>http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 14:21:46 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Serialization]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=200</guid>
		<description><![CDATA[I&#8217;ve encountered some odd behavior that I would have expected to work when calling readObject() to de-serialize an array of anonymous objects. If anyone knows what&#8217;s going on here, please enlighten me. I&#8217;ve also filed a bug on Adobe&#8217;s bug tracking system if anyone wants to follow the progress at Adobe&#8217;s end. I&#8217;m trying to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve encountered some odd behavior that I would have expected to work when calling <code>readObject()</code> to de-serialize an array of anonymous objects.  If anyone knows what&#8217;s going on here, please enlighten me.  I&#8217;ve also <a href="http://bugs.adobe.com/jira/browse/FP-601">filed a bug</a> on Adobe&#8217;s bug tracking system if anyone wants to follow the progress at Adobe&#8217;s end.</p>
<p>I&#8217;m trying to read all of the bytes in the <code>readExternal()</code> function of a class implementing <code>IExternalizable</code>, so that I may use the <code>position</code> property to move back in stream in case I need to do so.  The problem only seems to occur if I am trying to de-serialize an Array of anonymous objects.  If I put plain old Strings in the Array it will work fine.  I find this odd since I would expect</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span> = input.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>to have the exact same behavior as:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
  <span style="color: #000000; font-weight: bold;">var</span> inputBytes:uint = input.<span style="color: #006600;">bytesAvailable</span>;
  input.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>ba<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> baBytes:uint = ba.<span style="color: #006600;">bytesAvailable</span>;
  <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span> = ba.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;inputBytes == baBytes ?= &quot;</span> + <span style="color: #66cc66;">&#40;</span>inputBytes == baBytes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// traces &quot;inputBytes == baBytes ?= true</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>AIR installer and code attached below&#8230; <span id="more-200"></span></p>
<p>The classes I&#8217;m trying to serialize are simple as I&#8217;m only trying to serialize an Array in this test application.  (Excuse the poor code of assuming the items in the Array are Objects in the <code>toString()</code function).</p>
<h4>io/WorkingSerializer.as</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package io <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IExternalizable</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataInput</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataOutput</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WorkingSerializer <span style="color: #0066CC;">implements</span> IExternalizable <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> WorkingSerializer<span style="color: #66cc66;">&#40;</span>a:<span style="color: #0066CC;">Array</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			arr = a ? a : <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			arr = input.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> writeExternal<span style="color: #66cc66;">&#40;</span>output:IDataOutput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			output.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> arr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				s += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>{ &quot;</span>;
				<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> p:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> obj<span style="color: #66cc66;">&#41;</span>
					s += p + <span style="color: #ff0000;">&quot;: &quot;</span> + obj<span style="color: #66cc66;">&#91;</span>p<span style="color: #66cc66;">&#93;</span> + <span style="color: #ff0000;">&quot;,&quot;</span>;
				s += <span style="color: #ff0000;">&quot; }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;[WorkingSerializer]<span style="color: #000099; font-weight: bold;">\n</span> arr: [ &quot;</span> + s + <span style="color: #ff0000;">&quot;]&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>io/ProblemSerializer.as</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package io <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IExternalizable</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataInput</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataOutput</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProblemSerializer <span style="color: #0066CC;">implements</span> IExternalizable <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ProblemSerializer<span style="color: #66cc66;">&#40;</span>a:<span style="color: #0066CC;">Array</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			arr = a ? a : <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			input.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>ba<span style="color: #66cc66;">&#41;</span>;
			arr = ba.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> writeExternal<span style="color: #66cc66;">&#40;</span>output:IDataOutput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			output.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> arr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				s += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>{ &quot;</span>;
				<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> p:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> obj<span style="color: #66cc66;">&#41;</span>
					s += p + <span style="color: #ff0000;">&quot;: &quot;</span> + obj<span style="color: #66cc66;">&#91;</span>p<span style="color: #66cc66;">&#93;</span> + <span style="color: #ff0000;">&quot;,&quot;</span>;
				s += <span style="color: #ff0000;">&quot; }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;[ProblemSerializer]<span style="color: #000099; font-weight: bold;">\n</span> arr: [ &quot;</span> + s + <span style="color: #ff0000;">&quot;]&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And here is the main application file.  I wrote it as an <a href="http://www.adobe.com/go/air">AIR</a> application so install AIR first if you don't have it.</p>
<h4>SerializationIssue.mxml</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:WindowedApplication xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span>
						layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;500&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> io.<span style="color: #66cc66;">*</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> const WORKING:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;workingfile_v1&quot;</span>;
			<span style="color: #0066CC;">private</span> const PROBLEM:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;problemfile_v1&quot;</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				registerClassAlias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;io.WorkingSerializer&quot;</span>, io.<span style="color: #006600;">WorkingSerializer</span><span style="color: #66cc66;">&#41;</span>;
				registerClassAlias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;io.ProblemSerializer&quot;</span>, io.<span style="color: #006600;">ProblemSerializer</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> wo:WorkingSerializer = <span style="color: #000000; font-weight: bold;">new</span> WorkingSerializer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;some&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;items&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;are&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;here&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> s:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>getFile<span style="color: #66cc66;">&#40;</span>WORKING<span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>wo<span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> po:ProblemSerializer = <span style="color: #000000; font-weight: bold;">new</span> ProblemSerializer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;items&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;in&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;problem&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;serializer&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>getFile<span style="color: #66cc66;">&#40;</span>PROBLEM<span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>po<span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getFile<span style="color: #66cc66;">&#40;</span>filename:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:File <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> File.<span style="color: #006600;">applicationStorageDirectory</span>.<span style="color: #006600;">resolvePath</span><span style="color: #66cc66;">&#40;</span>filename<span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> readObj<span style="color: #66cc66;">&#40;</span>readWorking:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> s:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>getFile<span style="color: #66cc66;">&#40;</span>readWorking ? WORKING : PROBLEM<span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">READ</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>readWorking<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">var</span> wo:WorkingSerializer = s.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as WorkingSerializer;
					logger.<span style="color: #0066CC;">text</span> += wo + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>wo<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">var</span> po:ProblemSerializer = s.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ProblemSerializer;
					logger.<span style="color: #0066CC;">text</span> += po + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>po<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				s.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Read Working Serializer&quot;</span> click=<span style="color: #ff0000;">&quot;readObj(true)&quot;</span> <span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Read Problem Serializer&quot;</span> click=<span style="color: #ff0000;">&quot;readObj()&quot;</span> <span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Panel title=<span style="color: #ff0000;">&quot;Logging&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:TextArea id=<span style="color: #ff0000;">&quot;logger&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> editable=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #0066CC;">wordWrap</span>=<span style="color: #ff0000;">&quot;true&quot;</span>
					 updateComplete=<span style="color: #ff0000;">&quot;logger.verticalScrollPosition=logger.maxVerticalScrollPosition&quot;</span> <span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>To test this out without having to compile it yourself, I've compiled it as an AIR installer: <a href='http://blog.smartlogicsolutions.com/wp-content/uploads/2008/08/serializationissue.air'>Serialization Issue AIR Application</a>.  And the source: <a href='http://blog.smartlogicsolutions.com/wp-content/uploads/2008/08/serializationissue.zip'>Serialization Issue Source</a>.</p>
<p>When I run the code below and click on the "Read Working Serializer" button I correctly see:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>WorkingSerializer<span style="color: #66cc66;">&#93;</span>
 arr: <span style="color: #66cc66;">&#91;</span> 
	<span style="color: #66cc66;">&#123;</span> obj: some, <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#123;</span> obj: items, <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#123;</span> obj: are, <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#123;</span> obj: here, <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>get output to the console.  But, if I click on the "Read Problem Serializer" button I get the following RangeError:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">RangeError: <span style="color: #0066CC;">Error</span> <span style="color: #808080; font-style: italic;">#2006: The supplied index is out of bounds. </span>
at flash.<span style="color: #006600;">utils</span>::ByteArray<span style="color: #66cc66;">/</span>readObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
at io::ProblemSerializer<span style="color: #66cc66;">/</span>readExternal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&lt;</span>path to environment<span style="color: #66cc66;">&gt;/</span>SerializationIssue<span style="color: #66cc66;">/</span>src<span style="color: #66cc66;">/</span>io<span style="color: #66cc66;">/</span>ProblemSerializer.<span style="color: #006600;">as</span>:<span style="color: #cc66cc;">19</span><span style="color: #66cc66;">&#93;</span> 
at flash.<span style="color: #006600;">filesystem</span>::FileStream<span style="color: #66cc66;">/</span>readObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
at SerializationIssue<span style="color: #66cc66;">/</span>readObj<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&lt;</span>path to environment<span style="color: #66cc66;">&gt;/</span>SerializationIssue<span style="color: #66cc66;">/</span>src<span style="color: #66cc66;">/</span>SerializationIssue.<span style="color: #006600;">mxml</span>:<span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#93;</span> 
at SerializationIssue<span style="color: #66cc66;">/</span>___SerializationIssue_Button2_click<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&lt;</span>path to environment<span style="color: #66cc66;">&gt;/</span>SerializationIssue<span style="color: #66cc66;">/</span>src<span style="color: #66cc66;">/</span>SerializationIssue.<span style="color: #006600;">mxml</span>:<span style="color: #cc66cc;">51</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>In the meantime I'll find a workaround for this, but has anyone encountered anything similar to this or know why this isn't working?</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/07/16/creating-custom-layout-in-flex-4-gumbo/" rel="bookmark" class="crp_title">Creating a Custom Layout Class in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/11/losing-data-drag-and-drop-custom-class-flex-serialization/" rel="bookmark" class="crp_title">Losing Data When Drag and Dropping Custom Classes in Flex?</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/19/creating-custom-flex-4-skinnable-component/" rel="bookmark" class="crp_title">Creating Your First Custom SkinnableComponent in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/28/flex-4-login-form-component/" rel="bookmark" class="crp_title">Flex 4 Login Form Component</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/16/recreating-elys-flex-4-list-component-series/" rel="bookmark" class="crp_title">Recreating Ely&#8217;s Flex 4 List Component Series</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Losing Data When Drag and Dropping Custom Classes in Flex?</title>
		<link>http://blog.smartlogicsolutions.com/2008/07/11/losing-data-drag-and-drop-custom-class-flex-serialization/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/07/11/losing-data-drag-and-drop-custom-class-flex-serialization/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 05:13:51 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Serialization]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/2008/07/11/losing-data-drag-and-drop-custom-class-flex-serialization/</guid>
		<description><![CDATA[One of our developers recently encountered some strange behavior when he was dragging a piece of data (which was a custom class) from a TileList and dropping it into a List, but losing some pieces of the dragged data when it was dropped into the List. I discovered the root of the issue by delving [...]]]></description>
			<content:encoded><![CDATA[<p>One of our developers recently encountered some strange behavior when he was dragging a piece of data (which was a custom class) from a <code>TileList</code> and dropping it into a <code>List</code>, but losing some pieces of the dragged data when it was dropped into the <code>List</code>.  I discovered the root of the issue by delving into the source for the <code>dragDropHandler</code> function within <code>ListBase</code>&#8230;</p>
<p><span id="more-56"></span></p>
<p>the first clue was at line 9203 in the <code>mx.controls.listClasses.ListBase</code> class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">collectionIterator.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span>copyItemWithUID<span style="color: #66cc66;">&#40;</span>items<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Ah ha, now on to see what <code>copyItemWithUID</code> does, so looking at line 9230:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> copyObj:<span style="color: #0066CC;">Object</span> = ObjectUtil.<span style="color: #0066CC;">copy</span><span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>and the trail ends in <code>mx.utils.ObjectUtil</code> at line 102 in the copy function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> result:<span style="color: #0066CC;">Object</span> = buffer.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h3>The Problem and the Solution: Serialization</h3>
<p>Here I discovered the source of the problem.  The class that was being dragged was being properly serialized, but it had a property within it which was another custom class, and sure enough that class wasn&#8217;t being serialized.  This was causing that property to be lost &#8211; more specifically, it was becoming an empty Object.</p>
<p>If you don&#8217;t care how your class is serialized, but only that it will be properly serialized within Flex, then simply add the <code>[RemoteClass]</code> metadata tag above the class definition as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">example</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#93;</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySerializableClass <span style="color: #66cc66;">&#123;</span>
    ...
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/" rel="bookmark" class="crp_title">Serialization Error/Bug When Using a ByteArray and readObject in an IExternalizable Class?</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/16/creating-custom-layout-in-flex-4-gumbo/" rel="bookmark" class="crp_title">Creating a Custom Layout Class in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/17/migrairable-library-added-to-google-code/" rel="bookmark" class="crp_title">MigrAIRable Library Added to Google Code</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/16/recreating-elys-flex-4-list-component-series/" rel="bookmark" class="crp_title">Recreating Ely&#8217;s Flex 4 List Component Series</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/19/creating-custom-flex-4-skinnable-component/" rel="bookmark" class="crp_title">Creating Your First Custom SkinnableComponent in Flex 4</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/07/11/losing-data-drag-and-drop-custom-class-flex-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

