Releases: afollestad/ason
1.4.14
1.4.6
- Misc bug fixes
- Increased test coverage
1.4.5
- Fixed some bugs.
- Fixed some logic to make behavior more predictable.
- Increased test coverage.
1.4.4
Better handling of JSONObject.NULL
, added Ason.putNull(String)
. Added more test coverage.
1.4.3
Sorry about the frequent updates!
- Fixed a noticeable bug related to serializing arrays in objects.
- Greatly increased serialization performance, deserialization performance is next!
1.4.2
- Resolved https://github.com/afollestad/ason/issues/10 (technically fixed in version 1.4.1)
- Fixed some other vital issues related to
List
serialization/deserialization.
1.4.0
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
JDK 7 is targetted instead of JDK 8, resulting in better compatibility, especially on Android when Jack is not enabled.
1.3.0
1.2.0
- Periods in paths (dot notation) can be escaped if your keys actually have periods in them. Checkout the README!
- Increased test coverage.