Skip to content

Commit

Permalink
Merge pull request #36 from python-odin/1.x
Browse files Browse the repository at this point in the history
1.x
  • Loading branch information
timsavage committed Aug 1, 2017
2 parents a428b48 + cf9cf00 commit 069afc6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions odin/codecs/json_codec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import six
import datetime

from odin.utils import getmeta
Expand All @@ -12,6 +13,12 @@
except ImportError:
import json

LIST_TYPES = [bases.ResourceIterable]
if six.PY3:
import typing
LIST_TYPES += [typing.ValuesView, typing.KeysView]
LIST_TYPES = tuple(LIST_TYPES)

JSON_TYPES = {
datetime.date: serializers.date_iso_format,
datetime.time: serializers.time_iso_format,
Expand All @@ -36,11 +43,11 @@ def default(self, o):
if self.include_type_field:
obj[meta.type_field] = meta.resource_name
return obj
elif isinstance(o, bases.ResourceIterable):
elif isinstance(o, LIST_TYPES):
return list(o)
elif o.__class__ in JSON_TYPES:
return JSON_TYPES[o.__class__](o)
return super(OdinEncoder, self)
return super(OdinEncoder, self).default(o)


def load(fp, resource=None, full_clean=True, default_to_not_supplied=False):
Expand Down

0 comments on commit 069afc6

Please sign in to comment.