Centralize serialization/deserialization of resource models.

Review Request #6587 — Created Nov. 14, 2014 and submitted — Latest diff uploaded

Information

Review Board
release-2.0.x
7096395...

Reviewers

Previously, all JavaScript resource models were responsible for
implementing toJSON() and parseResourceData() functions. In many cases,
there were inconsistencies in how they handled certain
serialization/deserialization operations.

Along with this, we had no way of mapping attribute names to JSON
fields. This meant that, in some cases, calling code had to know about
the JSON fields in order to perform certain operations (like
fine-grained saving of fields).

Now, resources list the attributes to serialize and deserialize, and can
provide a map between attribute names and JSON field names. They can
also list custom serializers/deserializers for different fields. All
common serializers are provided in a new RB.JSONSerializers object.

This doesn't fully remove the need for toJSON or parseResourceData
functions, but most are gone. Most others can be removed down the road
if we centralize text type processing into a mixin.

An upcoming change will allow fine-grained saving of fields based on
attribute names, allowing us to make faster API calls with less impact
on the server.

All unit tests pass. We had some extensive testing already for
serialization/deserialization, but some more tests were added to
cover all cases.

I played around with reviews, replies, comments, review requests, and
file attachments, without any problems.

That said, we may hit some regression somewhere, but we'll need to do
some real-world testing.