﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22821	DjangoJSONEncoder no longer supports simplejson	Keryn Knight <django@…>	nobody	"For better or worse, `DjangoJSONEncoder`, despite living in the `core.serializers` package (and to my knowledge not being public API), is useful to support the few extra datatypes in standard json usage, and doesn't have any negative side affects. So it gets used.

Previously, in Django 1.4, `core.serializers.json` relied upon `simplejson`, but starting with 1.5 only used `json`.

Since then, `simplejson` has moved forward and has a slightly different API that prevents using `DjangoJSONEncoder`, because it subclasses `json.JSONEncoder` rather than `simplejson.JSONEncoder`, thus this worked in 1.4:
{{{
import simplejson as json
from django.core.serializers.json import DjangoJSONEncoder
json.dumps(""{}"", cls=DjangoJSONEncoder)
}}}
but in 1.5+, it yields a TypeError, with `simplejson==3.5.2`:
{{{
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/path/to/python2.7/site-packages/simplejson/__init__.py"", line 382, in dumps
    **kw).encode(obj)
TypeError: __init__() got an unexpected keyword argument 'namedtuple_as_object'
}}}
I think it ought to be possible to decouple the implementation such that people wanting to continue using simplejson could still benefit from the implementation of default, by doing something like (untested, pseudo-code):
{{{
class RichEncoder(object):
    def default(self, o):
        ...
        return (RichEncoder, self).default(o)

class DjangoJSONEncoder(RichEncoder, json.JSONEncoder): pass
DateTimeAwareJSONEncoder = DjangoJSONEncoder
}}}
meanwhile, userland implementations would replace the `json.JSONEncoder` part with `simplejson.JSONEncoder`, I guess.

This came up and bit someone in the IRC channel, and I'm reporting it because I ''think'' it's supportable, though it'd benefit me nought."	New feature	closed	Core (Serialization)	dev	Normal	wontfix			Unreviewed	0	0	0	0	0	0
