Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kemsky/JsonMapper

Typed JSON parser for ActionScript
https://github.com/kemsky/JsonMapper

adobe-air adobe-flash adobe-flex json-mapper json-serialization

Last synced: 3 months ago
JSON representation

Typed JSON parser for ActionScript

Awesome Lists containing this project

README

        

JsonMapper
==========

Typed JSON parser for ActionScript

Uses built-in [JSON](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/JSON.html) class if available,
also can fall back to pure ActionScript JSON parser [implementation](https://github.com/mikechambers/as3corelib).

Usage

1. Put annotations (`[Serialized(required=true/false)]` and `[ArrayElementType("type")]`):
```ActionScript
public class JsonVO
{
[Serialized(required="true")]
public var id:String = null;

[Serialized]
public var path:String = null;

[Serialized(required="false")]
public var name:String = null;

[Serialized]
public var description:String = null;

[Serialized]
public var value:Number;

[Serialized]
public var date:Date;

[Serialized]
[ArrayElementType("converter.rest.vo.JsonVO")]
public var properties:Array;

[Serialized]
[ArrayElementType("String")]
public var vector:Vector. = Vector.(["test", "test"]);

[Serialized]
[ArrayElementType("Boolean")]
public var booleans:Array = [[true, false], [true, false]];

[Serialized]
[ArrayElementType("converter.rest.vo.JsonVO")]
public var nested:Array = [];

[Serialized]
[ArrayElementType("int")]
public var aCollection:ArrayCollection = new ArrayCollection([1, 2, 3]);
}
```
2. Map entity:

```ActionScript
var mapper:JsonMapper = new JsonMapper();
mapper.registerClass(JsonVO);
```
3. Decode JSON:

```ActionScript
var result:JsonVO = new JsonDecoder(mapper).decode(message, JsonVO);
```

You can add metadata validation to Intellij Idea using KnownMetaData.dtd file.
Open `Preferences > Schemas and DTDs > Add` KnownMetaData.dtd with URI `urn:Flex:Meta`.