[ 
https://issues.apache.org/jira/browse/FLEX-27476?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Justin Mclean updated FLEX-27476:
---------------------------------

    Labels: easyfix easytest  (was: )
    
> XMLEncoder.isSimpleValue() method fails to detect decoded simpleContent 
> objects correctly
> -----------------------------------------------------------------------------------------
>
>                 Key: FLEX-27476
>                 URL: https://issues.apache.org/jira/browse/FLEX-27476
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: RPC: General
>    Affects Versions: Adobe Flex SDK 4.1 (Release)
>         Environment: Affected OS(s): All OS Platforms
> Affected OS(s): All OS Platforms
> Language Found: English
>            Reporter: Adobe JIRA
>              Labels: easyfix, easytest
>
>       Steps to reproduce:
> 1. Decode and then re-encode an XML file containing an element with 
> <xs:simpleContent/> using XMLDecoder and XMLEncoder.
> The re-encoded XML should match the original source XML.
> (See code example at bottom of description)
>  
>  Actual Results:
> <simple xsi:nil="true" id="foo" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
>  
>  Expected Results:
> <simple id="foo" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>bar</simple>
>  
>  
>  Workaround (if any):
>  
> XMLDecoder uses mx.rpc.xml.SimpleContent internally to decode simple content 
> into a dynamic object that behaves like a String (by overriding the valueOf 
> and toString methods)
> XMLEncoder.isSimpleValue incorrectly evaluates these objects to false. This 
> can be fixed by checking the type against value.valueOf() rather than just 
> the value
> public function isSimpleValue(value:*):Boolean
> {
>       value:* = value.valueOf();//this is change required
>       if (value is String || value is Number || value is Boolean
>                       || value is Date || value is int || value is uint
>                       || value is ByteArray)
>       {
>               return true;
>       }
>       return false;
> }
> Example Source:
> <?xml version="1.0" encoding="utf-8"?>
> <s:Application 
>               xmlns:fx="http://ns.adobe.com/mxml/2009";
>               xmlns:mx="library://ns.adobe.com/flex/mx"
>               xmlns:s="library://ns.adobe.com/flex/spark"
>               creationComplete="application1_creationCompleteHandler(event)"
>               minWidth="955" minHeight="600">
>       <fx:Script>
>               <![CDATA[
>                       import mx.events.FlexEvent;
>                       import mx.rpc.xml.Schema;
>                       import mx.rpc.xml.SchemaManager;
>                       import mx.rpc.xml.XMLDecoder;
>                       import mx.rpc.xml.XMLEncoder;
>                       protected function 
> application1_creationCompleteHandler(event:FlexEvent):void
>                       {
>                               var schema:Schema = new Schema(xsd);
>                               var manager:SchemaManager = new SchemaManager();
>                               manager.addSchema(schema);
>                               var decoder:XMLDecoder = new XMLDecoder();
>                               decoder.schemaManager = manager;
>                               var qName:QName = new QName("", "simple");
>                               var data:Object = decoder.decode(xml, qName);
>                               var encoder:XMLEncoder = new XMLEncoder();
>                               encoder.schemaManager = manager;
>                               var newXML:XML = encoder.encode(data, qName)[0];
>                               trace(newXML.toXMLString());
>                       }
>               ]]
>       >
>       </fx:Script>
>       <fx:Declarations>
>               <fx:XML xmlns="" id="xsd">
>                       <xs:schema 
>                                       
> xmlns:xs="http://www.w3.org/2001/XMLSchema";
>                                       elementFormDefault="qualified">
>                               <xs:element name="simple">
>                                       <xs:complexType>
>                                               <xs:simpleContent>
>                                                       <xs:extension 
> base="xs:string">
>                                                               <xs:attribute 
> name="id" type="xs:string" />
>                                                       </xs:extension>
>                                               </xs:simpleContent>
>                                       </xs:complexType>
>                               </xs:element>
>                       </xs:schema>
>               </fx:XML>
>               <fx:XML xmlns="" id="xml">
>                       <simple id="foo">bar</simple>
>               </fx:XML>
>       </fx:Declarations>
> </s:Application>
>     

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to