My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
QuickStart  
QuickStart to asx3m.
Updated Feb 4, 2010 by tpokraj...@gmail.com

Introduction

Here's a simple code that illustrates usage of asx3m library.
It defines two DTO classes and de/serializes them.
All public properties are serialized, no matter if they are defined over getter/setter or directly.

package hr.binaria.dto 
{
	public class Client
	{
		private var _age:int;
		
		public var id:Number;
		public var name:String;
		public var contacted:Boolean;
		public var mainProduct:Product;
		public var products:Array;
		
		public function get age():int{
			return _age;
		}
		public function set age(value:int):void {
			return _age;
		}
	}
}

package hr.binaria.dto
{
	public class Product
	{
		public var id:Number;
		public var name:String;
	}
}

package {
       import flash.display.Sprite;
	
       import hr.binaria.dto.Product;
       import hr.binaria.dto.Client;
       import hr.binaria.asx3m.Asx3mer;

	public class Asx3mTest extends Sprite
	{
                		
		public function Asx3mTest()
		{	
			
			var client:Client=new Client();				
			client.contacted=false;
			client.name="John";
			
			client.mainProduct=new Product();
			client.mainProduct.id=0;
			client.mainProduct.name="Main product";
			
			var prod1:Product=new Product();
			prod1.id=1;
			prod1.name="Product 1";
			var prod2:Product=new Product();
			prod2.id=2;
			prod2.name="Product 2";
			
			client.products=new Array;
			client.products.push(prod1);
			client.products.push(prod2);
						
			//convert object to XML
			var xmlObj:XML=Asx3mer.instance.toXML(client);
			trace(xmlObj);	

			//decode object from XML				
			var clientDecoded:Client=Asx3mer.instance.fromXML(xmlObj) as Client;				
			
			//convert object to xml forcing type	
			var xmlObjForced:XML=Asx3mer.instance.toXML(client,"SomeOtherType");
			trace(xmlObjForced);	
		}		
	}
}

Trace output is:

<hr.binaria.dto.Client>
  <name>John</name>
  <mainProduct>
    <name>Main product</name>
    <id>0</id>
  </mainProduct>
  <products>
    <hr.binaria.dto.Product>
      <name>Product 1</name>
      <id>1</id>
    </hr.binaria.dto.Product>
    <hr.binaria.dto.Product>
      <name>Product 2</name>
      <id>2</id>
    </hr.binaria.dto.Product>
  </products>
  <contacted>false</contacted>
</hr.binaria.dto.Client>

<SomeOtherType>
  <name>John</name>
  <mainProduct>
    <name>Main product</name>
    <id>0</id>
  </mainProduct>
  <products>
    <hr.binaria.dto.Product>
      <name>Product 1</name>
      <id>1</id>
    </hr.binaria.dto.Product>
    <hr.binaria.dto.Product>
      <name>Product 2</name>
      <id>2</id>
    </hr.binaria.dto.Product>
  </products>
  <contacted>false</contacted>
</SomeOtherType>
Comment by zhibo2...@gmail.com, Mar 21, 2010

asx3m_0.92.swc 版本,简析haspmap有问题asx3m_0.91.swc能够正常简析hashmap

Comment by derekspe...@gmail.com, Oct 14, 2011

Problem occurs when deserializing xml to HashMap? with version asx3m_0.92.swc


Sign in to add a comment
Powered by Google Project Hosting