<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Prevent Flex numeric nulls from turning to zeros in BlazeDS</title>
	<atom:link href="http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/feed" rel="self" type="application/rss+xml" />
	<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds</link>
	<description>A blog about our experience with Adobe Flex</description>
	<lastBuildDate>Tue, 31 Jan 2012 19:52:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Marcelo Daniel</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-77192</link>
		<dc:creator>Marcelo Daniel</dc:creator>
		<pubDate>Mon, 30 Aug 2010 01:59:05 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-77192</guid>
		<description>I love Farata!!!
Great Help
Bruce, You helped a lot too. 
Thanks</description>
		<content:encoded><![CDATA[<p>I love Farata!!!<br />
Great Help<br />
Bruce, You helped a lot too.<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruce Armstrong</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-68987</link>
		<dc:creator>Bruce Armstrong</dc:creator>
		<pubDate>Tue, 30 Mar 2010 18:15:40 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-68987</guid>
		<description>While the article addresses null values coming from Flex to Java we have taken one step further to make sure that nulls going from Java to Flex are being sent as NaN as well.

We just have to change  the file flex.messaging.io.amf.Amf3Output.java in BlazeDS source. All we are doing here is when an object is of type Long,Double,Integer,Float or Short and is null we convert the return value to Double.NaN in the DataOutputStream. This ensures that Flex gets Double.NaN on the receiving end. Note: The same change below should be made to flex.messaging.io.amf.Amf0Output.java if you are using the AMF0 format for ActionScript 1.0 and 2.0.

Class Amf3Output.java

    protected void writePropertyProxy(PropertyProxy proxy, Object instance) throws IOException
    {

        

        else if (propertyNames != null)
        {
            Iterator it = propertyNames.iterator();
            while (it.hasNext())
            {
                String propName = (String)it.next();
                Object value = null;
                value = proxy.getValue(instance, propName);
                
			// IDS - Start of changes - 01/10/2010
				value = proxy.getValue(instance, propName);
				if (IdsObjectHelper.isNullNumber(instance,propName,value))
					writeAMFDouble(Double.NaN);		
				else
			// IDS - End of Changes - 01/10/2010
                writeObjectProperty(propName, value);
            
            }
        }

        writeObjectEnd();
    }

    

And the helper class:

package com.ids.foundation.flex.messaging.io;

import java.lang.reflect.Field;

public class IdsObjectHelper {
	
	static boolean useCustomLogic = true;  
	
	public static boolean isNullNumber(Object object, String propName, Object value) {
		Field[] fields = object.getClass().getDeclaredFields();	
		
		if (value != null &#124;&#124; !useCustomLogic)
			return false;
		
		for (int index = 0; index &lt; fields.length; index++) {
			if (fields[index].getName().equals(propName)) {
				if (fields[index].getType().isInstance(new Integer(0)))
					return true;
				else if (fields[index].getType().isInstance(new Double(0)))
					return true;
				else if (fields[index].getType().isInstance(new Long(0)))
					return true;
				else if (fields[index].getType().isInstance(new Float(0)))
					return true;
				else if (fields[index].getType().isInstance(new Short((short)0)))
					return true;
				else
					return false;
			}
		}		
		return false;
	}

}</description>
		<content:encoded><![CDATA[<p>While the article addresses null values coming from Flex to Java we have taken one step further to make sure that nulls going from Java to Flex are being sent as NaN as well.</p>
<p>We just have to change  the file flex.messaging.io.amf.Amf3Output.java in BlazeDS source. All we are doing here is when an object is of type Long,Double,Integer,Float or Short and is null we convert the return value to Double.NaN in the DataOutputStream. This ensures that Flex gets Double.NaN on the receiving end. Note: The same change below should be made to flex.messaging.io.amf.Amf0Output.java if you are using the AMF0 format for ActionScript 1.0 and 2.0.</p>
<p>Class Amf3Output.java</p>
<p>    protected void writePropertyProxy(PropertyProxy proxy, Object instance) throws IOException<br />
    {</p>
<p>        else if (propertyNames != null)<br />
        {<br />
            Iterator it = propertyNames.iterator();<br />
            while (it.hasNext())<br />
            {<br />
                String propName = (String)it.next();<br />
                Object value = null;<br />
                value = proxy.getValue(instance, propName);</p>
<p>			// IDS &#8211; Start of changes &#8211; 01/10/2010<br />
				value = proxy.getValue(instance, propName);<br />
				if (IdsObjectHelper.isNullNumber(instance,propName,value))<br />
					writeAMFDouble(Double.NaN);<br />
				else<br />
			// IDS &#8211; End of Changes &#8211; 01/10/2010<br />
                writeObjectProperty(propName, value);</p>
<p>            }<br />
        }</p>
<p>        writeObjectEnd();<br />
    }</p>
<p>And the helper class:</p>
<p>package com.ids.foundation.flex.messaging.io;</p>
<p>import java.lang.reflect.Field;</p>
<p>public class IdsObjectHelper {</p>
<p>	static boolean useCustomLogic = true;  </p>
<p>	public static boolean isNullNumber(Object object, String propName, Object value) {<br />
		Field[] fields = object.getClass().getDeclaredFields();	</p>
<p>		if (value != null || !useCustomLogic)<br />
			return false;</p>
<p>		for (int index = 0; index &lt; fields.length; index++) {<br />
			if (fields[index].getName().equals(propName)) {<br />
				if (fields[index].getType().isInstance(new Integer(0)))<br />
					return true;<br />
				else if (fields[index].getType().isInstance(new Double(0)))<br />
					return true;<br />
				else if (fields[index].getType().isInstance(new Long(0)))<br />
					return true;<br />
				else if (fields[index].getType().isInstance(new Float(0)))<br />
					return true;<br />
				else if (fields[index].getType().isInstance(new Short((short)0)))<br />
					return true;<br />
				else<br />
					return false;<br />
			}<br />
		}<br />
		return false;<br />
	}</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kim Hansen</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-67974</link>
		<dc:creator>Kim Hansen</dc:creator>
		<pubDate>Thu, 25 Mar 2010 11:48:07 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-67974</guid>
		<description>Hi Victor,

I have implemented your solution and it works like a charm. Thanks a lot!

This seems to be a big bug with BlazeDS, so I hope they will fix it soon.

Kim</description>
		<content:encoded><![CDATA[<p>Hi Victor,</p>
<p>I have implemented your solution and it works like a charm. Thanks a lot!</p>
<p>This seems to be a big bug with BlazeDS, so I hope they will fix it soon.</p>
<p>Kim</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ziv</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-55697</link>
		<dc:creator>ziv</dc:creator>
		<pubDate>Tue, 02 Feb 2010 16:45:12 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-55697</guid>
		<description>Hi, Thanks!!

Is it support both ways? means, from the Java to AS and from the AS to Java ?

i understand that it simply upgrade the decoder , but what about the encoder?

Ziv</description>
		<content:encoded><![CDATA[<p>Hi, Thanks!!</p>
<p>Is it support both ways? means, from the Java to AS and from the AS to Java ?</p>
<p>i understand that it simply upgrade the decoder , but what about the encoder?</p>
<p>Ziv</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor Rasputnis</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-50429</link>
		<dc:creator>Victor Rasputnis</dc:creator>
		<pubDate>Fri, 15 Jan 2010 05:13:34 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-50429</guid>
		<description>Nono,

Please read  my next post: rebuild of the BlazeDS can be avoided by using so called &lt;a href=&quot;http://flexblog.faratasystems.com/2010/01/09/custom-type-masrhaller-in-blazeds&quot; rel=&quot;nofollow&quot;&gt;Custom Marshaller&lt;/a&gt;.
In that case you would resolve the issue with two classes: CustomMarshaller, that gets configured per Endpoint in the services-config.xml and NumberDecoder. 

WBR,
Victor</description>
		<content:encoded><![CDATA[<p>Nono,</p>
<p>Please read  my next post: rebuild of the BlazeDS can be avoided by using so called <a href="http://flexblog.faratasystems.com/2010/01/09/custom-type-masrhaller-in-blazeds" rel="nofollow">Custom Marshaller</a>.<br />
In that case you would resolve the issue with two classes: CustomMarshaller, that gets configured per Endpoint in the services-config.xml and NumberDecoder. </p>
<p>WBR,<br />
Victor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nono Carballo</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-49737</link>
		<dc:creator>Nono Carballo</dc:creator>
		<pubDate>Mon, 11 Jan 2010 17:02:09 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-49737</guid>
		<description>Is there other way to accomplish this without rebuilding blazeDS?
I have seen there is a class ASTranslator, could this class serve to this purpose?
Maybe extending from ASTranslator and registering the new translator in services-config.xml?

Nono</description>
		<content:encoded><![CDATA[<p>Is there other way to accomplish this without rebuilding blazeDS?<br />
I have seen there is a class ASTranslator, could this class serve to this purpose?<br />
Maybe extending from ASTranslator and registering the new translator in services-config.xml?</p>
<p>Nono</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruce Armstrong</title>
		<link>http://flexblog.faratasystems.com/2010/01/07/how-to-keep-numeric-null-value-from-turning-into-zeros-in-blazeds/comment-page-1#comment-49509</link>
		<dc:creator>Bruce Armstrong</dc:creator>
		<pubDate>Sat, 09 Jan 2010 04:26:18 +0000</pubDate>
		<guid isPermaLink="false">http://flexblog.faratasystems.com/?p=515#comment-49509</guid>
		<description>Thanks Victor!   That looks great.  Exactly what I needed.</description>
		<content:encoded><![CDATA[<p>Thanks Victor!   That looks great.  Exactly what I needed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

