From b291df23816023cc47bd609d1ed35c3076c2d526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 11 Jan 2021 00:11:25 +0100 Subject: [PATCH] Encode Decimal with it primitive value for PYSON Otherwise the Decimal is duplicated as a generic Object by the preparation. issue9852 review330001002 --- src/pyson.js | 2 ++ tests/sao.js | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/pyson.js b/src/pyson.js index 32e035a029..7e7783dba2 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -85,6 +85,8 @@ value.seconds(), value.milliseconds() * 1000).pyson(); } + } else if (value instanceof Sao.Decimal) { + value = value.valueOf(); } else if ((value instanceof Object) && !(value instanceof Sao.PYSON.PYSON)) { value = jQuery.extend({}, value); diff --git a/tests/sao.js b/tests/sao.js index 3e2e2f35d7..129ab6efea 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -45,6 +45,8 @@ QUnit.test('PYSON Encoder', function() { var encoder = new Sao.PYSON.Encoder(); var none; + var decimal = Sao.Decimal(1.1); + var pyson_decimal = 1.1; var date = Sao.Date(2002, 0, 1); var datetime = Sao.DateTime(2002, 0, 1, 12, 30, 0, 0); var pyson_date = new Sao.PYSON.Date(2002, 1, 1).pyson(); @@ -63,6 +65,8 @@ QUnit.strictEqual(encoder.encode(), 'null', "encode()"); QUnit.strictEqual(encoder.encode(none), 'null', "encode(none)"); QUnit.strictEqual(encoder.encode(null), 'null', "encode()"); + QUnit.strictEqual(encoder.encode(decimal), + JSON.stringify(pyson_decimal), "encode(decimal)"); QUnit.strictEqual(encoder.encode(date), JSON.stringify(pyson_date), "encode(date)"); QUnit.strictEqual(encoder.encode(datetime),