Allow object-defined JSON serialization in JSONField/DjbletsJSONEncoder.
Review Request #8350 — Created Aug. 26, 2016 and submitted — Latest diff uploaded
DjbletsJSONEncoderallowed models to define ato_json()method, which
would be called when an instance of that model was encountered. Since
this is useful outside of models, the encoder's been updated to support
this on any object, making it much easier to encode content in places
like integration or site configuration storage.
JSONFieldhas also been updated to make use ofDjbletsJSONEncoder,
bringing those same benefits to any models that use that.In order to keep all existing encoder usage from changing any behavior
with datetimes,DjbletsJSONEncodernow acceps a strip_datetime_ms
parameter, defaulting toTruefor compatibility reasons.JSONField
turns this off.
Unit tests pass.
Tested that a
JSONFieldI was using in Review Board was able to
serialize an object with ato_jsonmethod.