Skip to content
XML to Object (and vice versa) mapping library written in AS3. Compatible with XStream.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


AStream can handle enums. Enum's name passed to super() is used to represent enum's value in XML.

package com.example.domain {
import as3.lang.Enum;

public class UserRole extends Enum {
    public static const ADMINISTRATOR:UserRole = new UserRole("ROLE_ADMINISTRATOR");
    public static const OPERATOR:UserRole = new UserRole("ROLE_OPERATOR");

    public function UserRole(name:String) {

There is no guarantee in flash that you will get class' properies in order they were declared!

You can add AStreamOrder metadata to enforce tag order in xml.

package com.example.domain {
public class User {
    private var _name:String;

    public var id:Number;
    public var role:UserRole;
    [AStreamConverter("ru.kokorin.astream.converter.DateConverter", params="yyyy-MM-dd")]
    public var birth:Date;

    public function User() {

    public function get name():String {
        return _name;

    public function set name(value:String):void {
        _name = value;

    public function toString():String {
        return "User{name=" + String(name) + ",id=" + String(id) + ",role=" + String(role) + ",birth=" + String(birth) + "}";

Use AStream's metadata autodetection with caution!

If metadata autodetection is on, every time AStream converts an object it will first process the object's type and all the types related. Therefore it is no problem to serialize an object graph into XML, since AStream will know of all types in advance.

This is no longer true at deserialization time. AStream has to know the alias to turn it into the proper type, but it can find the annotation for the alias only if it has processed the type in advance. Therefore deserialization will fail if the type has not already been processed either by having called AStream's processMetadata method or by already having serialized this type. However, AStreamAlias is the only metadata that may fail in this case.

const aStream:AStream = new AStream();
//or aStream.autodetectMetadata(true);

const user:User = new User(); = 1; = "Ivanov Ivan";
user.role = UserRole.ADMINISTRATOR;
user.birth = new Date(1960, 4, 19, 0, 0, 0, 0);

const xml:XML = aStream.toXML(user);
/* xml.toXMLString()
    <name>Ivanov Ivan</name>
 </User> */

const restoredUser:User = aStream.fromXML(xml) as User;
/* restoredUser.toString()
User{name=Ivanov Ivan,id=1,role=ROLE_ADMINISTRATOR,birth=Thu May 19 00:00:00 GMT+0300 1960} */

Сorresponding types (by default)

     Java        |         XML         |                AS3       

---------------------|---------------------|------------------------------------ byte[] | byte-array | ByteArray Type[] | Type-array | Vector.<Type> java.util.ArrayList | list | org.spicefactory.lib.collection.List java.util.HashMap | map | org.spicefactory.lib.collection.Map Float, float | float | Number
Integer, int | int | int
java.util.Date | date | Date java.lang.String | string | String

You can’t perform that action at this time.