Ason Versions Save

[DEPRECATED]: Prefer Moshi, Jackson, Gson, or LoganSquare

1.4.14

6 years ago

Recursive serialization and deserialization; include fields in super classes.

1.4.6

7 years ago
  1. Misc bug fixes
  2. Increased test coverage

1.4.5

7 years ago
  1. Fixed some bugs.
  2. Fixed some logic to make behavior more predictable.
  3. Increased test coverage.

1.4.4

7 years ago

Better handling of JSONObject.NULL, added Ason.putNull(String). Added more test coverage.

1.4.3

7 years ago

Sorry about the frequent updates!

  1. Fixed a noticeable bug related to serializing arrays in objects.
  2. Greatly increased serialization performance, deserialization performance is next!

1.4.2

7 years ago
  1. Resolved https://github.com/afollestad/ason/issues/10 (technically fixed in version 1.4.1)
  2. Fixed some other vital issues related to List serialization/deserialization.

1.4.0

7 years ago

More abilities in Index Notation!

To extend on dot notations in paths, you can use this notation to perform operations on array children.

Take this JSON:

{
    "group_id": 1,
    "title": "Hello, world!",
    "participants": [
        {
            "name": "Aidan",
            "id": 2
        },
        {
            "name": "Waverly",
            "id": 1
        }
    ]
}

You could create this using index notation as such:

Ason ason = new Ason()
    .put("group_id", 1)
    .put("title", "Hello, world!")
    .put("participants.$0.name", "Aidan")
    .put("participants.$0.id", 2)
    .put("participants.$1.name", "Waverly")
    .put("participants.$1.id", 1);

The dollar sign followed by the number 0 indicates that you want the item at index 0 (position 1) within an array called "participants".


You can retrieve the value of "name" in the second participant like this:

Ason object = // ...
String name = object.get("participants.$1.name");

If you wanted to remove the first item from the inner array, you can do that with index notation. This avoids the need to first retrieve the "participants" object:

Ason object = // ...
object.remove("participants.$0");

Dot Notation has also been improved, here's the latest docs!

Lets create an object using a few dot notation keys:

Ason ason = new Ason()
    .put("id", 1)
    .put("name", "Aidan")
    .put("birthday.month", "July")
    .put("birthday.day", 28)
    .put("birthday.year", 1995);

The above would construct this:

{
    "id": 1,
    "name": "Aidan",
    "birthday": {
        "month": "July",
        "day": 28,
        "year": 1995
    }
}

As you can see, a child object is automatically created for you. We only use two levels, but you could create many more just by using more periods to separate child names.


You can retrieve values from objects using dot notation:

Ason ason = // ...

String name = ason.get("name");
String month = ason.get("birthday.month");
int day = ason.get("birthday.day");
int year = ason.get("birthday.year");

If you wanted to remove the inner "year" value:

Ason ason = // ...
ason.remove("birthday.year");

You can use dot notation with arrays too, but you need to specify the index of the object to pull from:

AsonArray ason = // ...
String name = ason.get(1, "birthday.month");

As a bonus, you can check equality without doing a manual value comparison:

Ason ason = // ...
boolean birthYearCheck = ason.equal("birthday.year", 1995);

AsonArray ason2 = // ...
boolean birthYearCheck2 = ason2.equal(2, "birthday.year", 1995);

1.3.1

7 years ago

JDK 7 is targetted instead of JDK 8, resulting in better compatibility, especially on Android when Jack is not enabled.

1.3.0

7 years ago

Index Notation!

A new feature to be used along side dot notation:


capture


I also massively increased test coverage for the library.

1.2.0

7 years ago
  1. Periods in paths (dot notation) can be escaped if your keys actually have periods in them. Checkout the README!
  2. Increased test coverage.