Skip to content

Commit

Permalink
Merge pull request #3 from mjsqu/fix/output_decimal_decimal_as_number
Browse files Browse the repository at this point in the history
Bugfix: output decimal.Decimal as number not string to comply with JSONSchema
  • Loading branch information
mjsqu authored Mar 22, 2023
2 parents 3eaf3ec + b33009a commit 0f5497f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.2 (2022-03-23)
* Using orjson instead of simplejson or other serializers for speed benefit
* Fix: Output decimal.Decimal as int or float not str

## 2.0.1 (2021-11-23)
* Fixed an issue when `format_message` returned newline character

Expand Down
2 changes: 1 addition & 1 deletion singer/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def parse_message(msg):
def format_message(message, option=0):
def default(obj):
if isinstance(obj, decimal.Decimal):
return str(obj)
return int(obj) if float(obj).is_integer() else float(obj)
raise TypeError

return orjson.dumps(message.asdict(), option=option, default=default)
Expand Down

0 comments on commit 0f5497f

Please sign in to comment.