Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kokorin/AStream
XML to Object (and vice versa) mapping library written in AS3. Compatible with XStream.
https://github.com/kokorin/AStream
Last synced: 3 months ago
JSON representation
XML to Object (and vice versa) mapping library written in AS3. Compatible with XStream.
- Host: GitHub
- URL: https://github.com/kokorin/AStream
- Owner: kokorin
- License: apache-2.0
- Created: 2014-05-06T04:53:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-16T10:08:55.000Z (over 9 years ago)
- Last Synced: 2024-05-28T22:38:55.178Z (5 months ago)
- Language: ActionScript
- Homepage:
- Size: 615 KB
- Stars: 8
- Watchers: 7
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-actionscript-sorted - AStream - XML to Object (and vice versa) mapping library written in AS3. Compatible with XStream. (File Formats / XML)
README
AStream
=======AStream can handle enums. Enum's name passed to super() is used to represent enum's value in XML.
```as3
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) {
super(name);
}
}
}
```**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.
```as3
package com.example.domain {
[AStreamAlias("User")]
public class User {
private var _name:String;[AStreamOrder(10)]
public var id:Number;
[AStreamOrder(30)]
public var role:UserRole;
[AStreamOrder(40)]
[AStreamConverter("ru.kokorin.astream.converter.DateConverter", params="yyyy-MM-dd")]
public var birth:Date;public function User() {
}[AStreamOrder(20)]
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.
```as3
const aStream:AStream = new AStream();
aStream.processMetadata(User);
//or aStream.autodetectMetadata(true);const user:User = new User();
user.id = 1;
user.name = "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()
1
Ivanov Ivan
ROLE_ADMINISTRATOR
1960-05-19
*/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