[New-bugs-announce] [issue5535] json custom encoder not fully functionnal

Pierre Hanser report at bugs.python.org
Sun Mar 22 09:03:40 CET 2009

New submission from Pierre Hanser <hanser at club-internet.fr>:

The json module provides an encoder python -> json.
The encoding may be specialized by the user, using
the cls parameter of the dumps function.

But all simple types are always handled by the library encoder,
the user encoder is only used as a last resort one, for unknown types.

This is not described nor intuitive, and it prevents specifying a custom
encoder for classes which inherit from simple type.

in the provided example (thanks Raymond) a user defined boolean
type, inheriting from int, is handled as int where you would prefer
it to be handled as a json boolean through a custom encoder.

problem seen on simplejson-2.0.9 or official python 2.6.1

components: Library (Lib)
files: jsonCustomEncoder.py
messages: 83962
nosy: phanser
severity: normal
status: open
title: json custom encoder not fully functionnal
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file13393/jsonCustomEncoder.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list