Skip to content

Commit

Permalink
adding logic to serialize bytes and bytearray datatypes to string
Browse files Browse the repository at this point in the history
  • Loading branch information
awskaran committed Jan 12, 2024
1 parent 8b34dd5 commit 4a1228a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/dataall/base/utils/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def json_decoder(x):
return str(x)
if hasattr(x, '__table__'):
return to_json(x)
if isinstance(x, bytes):
return str(x)
if isinstance(x, bytearray):
return str(x)
return x


Expand Down Expand Up @@ -56,6 +60,8 @@ def to_json(record):
(datetime.now() - startquery).total_seconds(),
)
return to_json(items)
elif type(record) in [bytes, bytearray]:
return json_decoder(record)
else:
return json.loads(json.dumps(record.to_dict(), default=json_decoder))

Expand Down

0 comments on commit 4a1228a

Please sign in to comment.