Allow object-defined JSON serialization in JSONField/DjbletsJSONEncoder.
Review Request #8350 — Created Aug. 26, 2016 and submitted
DjbletsJSONEncoder
allowed 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.
JSONField
has 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,DjbletsJSONEncoder
now acceps a strip_datetime_ms
parameter, defaulting toTrue
for compatibility reasons.JSONField
turns this off.
Unit tests pass.
Tested that a
JSONField
I was using in Review Board was able to
serialize an object with ato_json
method.
Description | From | Last Updated |
---|---|---|
'models' imported but unused |
reviewbot |
- Change Summary:
-
Removed an unused import.
- Commit:
-
1e1c723bf6d4f6c27c7cdf5967ad7fed48166e6586e6cd078dcaf0575f7ad4b27bd999ae1fe74790