Skip to content

Latest commit

 

History

History
110 lines (79 loc) · 3.61 KB

README.md

File metadata and controls

110 lines (79 loc) · 3.61 KB

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.

  • You're using an existing JSON-based REST API

    • You'll probably find using ceylon.json directly better fits your needs, because Alabama is not very configurable for parsing arbitrary JSON into Ceylon objects.
  • You're running on the JVM and need interop with Java code

    • Ceylon classes look like Java beans underneath, so libraries like Jackson and Gson should work OK.

    • Most Ceylon classes are Java-Serializable, so
      Java serialization if work for you, if you're not tied to JSON

  • You need "long term persistence"

    • Alabama is still evolving, and does not support schema evolution, so the JSON emitted might change even if your classes do not.
  • You're in an all-Ceylon world, or there are no existing consumers for your JSON and you're not super bothered about controlling every aspect of what your JSON looks like

    • Alabama is for you
  • Speed is the most important thing for you.

    • Alabama prioritises preserving Ceylon semantics. If you need blazingly fast you might be prepared to compromise on that.

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!!!