tombentley / alabama

A JSON-based Ceylon serialization library
Other
6 stars 2 forks source link

Alabama

Alabama is a serialization library for Ceylon. It uses the ceylon.language.serialization API to provide idiomatic roundtrip serialization to and from JSON.

tl;dr: example

Features

round trip (to JSON and back) Yes
readable output Yes1
cross-VM (JVM <-> JSON <-> JS) Yes2
identity-preserving Yes
supports reference cycles Yes
late attributes Yes
toplevel classes Yes, obviously
toplevel objects Yes
member classes No
member objects No
streaming Not yet
blazingly fast No
compact output Not really3


1 Obviously features such as "identity-preserving" require we add extra information to the JSON, but we try to do this in an idiomatic way.

2 "JS" meaning Ceylon running on a JS VM, but obviously it's JSON so you can have a plain JS client if you want.

3 That's what gzip is for ;-)

Non-goals

Alabama may or may not be the right choice for you, depending on what you're trying to achieve.

Example

OK, here's some Ceylon code:

serializable class Person(first, last, address) {
    shared String first;
    shared String last;
    shared Address address;
}
serializable class Address(lines, zip) {
    [String+] lines;
    String zip;
}

value p = Person {
    first = "Tom";
    last = "Bentley";
    address = Address {
        lines = ["Jackson", "Alabama"]; 
        zip="1234";
    };
};

String json = serialize(p);
Person p2 = deserialize<Person>(json);

And in case you're interested, this is what the JSON looks like:

TODO!!!