diff --git a/awslambdaric/lambda_runtime_marshaller.py b/awslambdaric/lambda_runtime_marshaller.py index 7eee25d..b591e69 100644 --- a/awslambdaric/lambda_runtime_marshaller.py +++ b/awslambdaric/lambda_runtime_marshaller.py @@ -12,9 +12,10 @@ # simplejson's Decimal encoding allows '-NaN' as an output, which is a parse error for json.loads # to get the good parts of Decimal support, we'll special-case NaN decimals and otherwise duplicate the encoding for decimals the same way simplejson does +# We also set 'ensure_ascii=False' so that the encoded json contains unicode characters instead of unicode escape sequences class Encoder(json.JSONEncoder): def __init__(self): - super().__init__(use_decimal=False) + super().__init__(use_decimal=False, ensure_ascii=False) def default(self, obj): if isinstance(obj, decimal.Decimal): diff --git a/requirements/base.txt b/requirements/base.txt index 614d435..515470b 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1 +1 @@ -simplejson==3.17.2 +simplejson==3.17.6 diff --git a/tests/test_lambda_runtime_marshaller.py b/tests/test_lambda_runtime_marshaller.py index 8268de1..eeb2715 100644 --- a/tests/test_lambda_runtime_marshaller.py +++ b/tests/test_lambda_runtime_marshaller.py @@ -37,3 +37,9 @@ def test_json_serializer_is_not_default_json(self): self.assertTrue(hasattr(internal_json, "YOLO")) self.assertFalse(hasattr(stock_json, "YOLO")) self.assertTrue(hasattr(simplejson, "YOLO")) + + def test_to_json_unicode_encoding(self): + response = to_json({"price": "£1.00"}) + self.assertEqual('{"price": "£1.00"}', response) + self.assertNotEqual('{"price": "\\u00a31.00"}', response) + self.assertEqual(19, len(response.encode('utf-8'))) # would be 23 bytes if a unicode escape was returned