Adding ability to encode custom objects

Encoding custom objects in an agonstic manner is difficult right now,
since there's no way to ensure that a custom encoder will be used. This
patch lets custom objects use a __json__ method to output an appropriate
value.