From 9b8a387ab4e866b6049b28d83e9401daf670e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 25 Jul 2017 18:21:23 +0200 Subject: [PATCH] Add JSONEncoder --- pymispgalaxies/__init__.py | 2 +- pymispgalaxies/api.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pymispgalaxies/__init__.py b/pymispgalaxies/__init__.py index 3c9f1da..795d66f 100644 --- a/pymispgalaxies/__init__.py +++ b/pymispgalaxies/__init__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from .api import Galaxies, Clusters +from .api import Galaxies, Clusters, EncodeGalaxies diff --git a/pymispgalaxies/api.py b/pymispgalaxies/api.py index 13add5e..de25579 100644 --- a/pymispgalaxies/api.py +++ b/pymispgalaxies/api.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import json +from json import JSONEncoder import os import sys import collections @@ -14,6 +15,14 @@ except ImportError: HAS_JSONSCHEMA = False +class EncodeGalaxies(JSONEncoder): + def default(self, obj): + try: + return obj._json() + except AttributeError: + return JSONEncoder.default(self, obj) + + class Galaxy(): def __init__(self, galaxy):