Skip to content

Commit

Permalink
Also handle date and datetime object when serializing to json
Browse files Browse the repository at this point in the history
I noticed suds can generate such type.
  • Loading branch information
philpep committed Jan 5, 2022
1 parent 7efc7b6 commit 32f8872
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lowatt_enedis/__init__.py
Expand Up @@ -21,6 +21,7 @@
Command line interface to enedis SGE web-services.
"""

import datetime
import json
import logging
import sys
Expand Down Expand Up @@ -100,6 +101,8 @@ def init_cli(subparsers):
def json_encode_default(obj: Any) -> Any:
if isinstance(obj, suds.sudsobject.Object):
return suds.sudsobject.asdict(obj)
elif isinstance(obj, (datetime.date, datetime.datetime)):
return obj.isoformat()
raise TypeError(f"Object {obj!r} is not JSON serializable")


Expand Down

0 comments on commit 32f8872

Please sign in to comment.