Allow object-defined JSON serialization in JSONField/DjbletsJSONEncoder.

Review Request #8350 — Created Aug. 26, 2016 and submitted

Information

Djblets
release-0.10.x
86e6cd0...

Reviewers

DjbletsJSONEncoderallowed models to define a to_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 of DjbletsJSONEncoder,
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 to True 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 a to_json method.

Description From Last Updated

'models' imported but unused

reviewbotreviewbot
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/util/tests.py
        djblets/db/fields.py
        djblets/util/serializers.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/util/tests.py
        djblets/db/fields.py
        djblets/util/serializers.py
    
    
  2. djblets/util/tests.py (Diff revision 1)
     
     
    Show all issues
     'models' imported but unused
    
  3. 
      
chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/util/tests.py
        djblets/db/fields.py
        djblets/util/serializers.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/util/tests.py
        djblets/db/fields.py
        djblets/util/serializers.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.10.x (104c7d9)