Skip to content

Commit

Permalink
Merge branch 'master' into public_master
Browse files Browse the repository at this point in the history
  • Loading branch information
franzlst committed Sep 27, 2017
2 parents 1d47702 + 8e6f5bf commit a5d1be2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/jsonconversion/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from json.encoder import JSONEncoder, _make_iterencode, encode_basestring_ascii, FLOAT_REPR, INFINITY, \
encode_basestring
from inspect import isclass
from inspect import isclass, getargspec
from types import ClassType
try:
import numpy as np
Expand Down Expand Up @@ -93,13 +93,14 @@ class JSONObjectEncoder(JSONExtendedEncoder):
"""

def __init__(self, **kwargs):
for key in ['use_decimal', 'namedtuple_as_object', 'tuple_as_array', 'bigint_as_string', 'item_sort_key',
'for_json', 'ignore_nan']:
try:
# Depending on the version of json, the allowed arguments differ.
# Therefore we have to remove unsupported arguments.
parental_constructor = super(JSONObjectEncoder, self).__init__
parental_constructor_args = getargspec(parental_constructor).args
for key in kwargs.keys():
if key not in parental_constructor_args:
del kwargs[key]
except KeyError:
pass
super(JSONObjectEncoder, self).__init__(**kwargs)
parental_constructor(**kwargs)

def isinstance(self, obj, cls):
if isinstance(obj, (set, tuple)):
Expand Down

0 comments on commit a5d1be2

Please sign in to comment.