From ada532ec3dea5e3065840e436496fb0bbce45193 Mon Sep 17 00:00:00 2001 From: Steffen Agger Date: Wed, 2 Dec 2020 23:35:45 +0100 Subject: [PATCH] Rolling back PR 3356, toJSON should not make assumptions as to how ArrayBuffers are serialized --- CHANGELOG.md | 1 - lib/extensions.js | 16 +++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 149f992b4a..41e331edcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ x.x.x Release notes (yyyy-MM-dd) ### Fixed * Fixed an issue in `toJSON()`, in combination with primaryKeys, where data from another table could be returned. ([#3331](https://github.com/realm/realm-js/issues/3331), since v10.0.0) -* Fixed an issue in `toJSON()` where `data` would output as `{}`, it now returns the data base64 encoded. ([#3356](https://github.com/realm/realm-js/pull/3356), since v10.0.0) * TS: `RealmInsertionModel` used in `realm.create(...)` now ignores functions on Class Models. ([#3421](https://github.com/realm/realm-js/pull/3421), since v10.0.0) ### Compatibility diff --git a/lib/extensions.js b/lib/extensions.js index 2f2fd8aae3..1ac3bd97f3 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -123,19 +123,13 @@ module.exports = function(realmConstructor, context) { // skip any functions & constructors (in case of class models). if (typeof value === "function") { - return; // continue + return; // continue } - if (value instanceof realmConstructor.Object || value instanceof realmConstructor.Collection) { - // recursively trigger `toJSON` for Realm instances with the same cache. - result[key] = value.toJSON(key, cache); - } else if (value instanceof ArrayBuffer) { - // convert "data" to base64 strings. - result[key] = Buffer.from(value).toString("base64"); - } else { - // default to original value. - result[key] = value; - } + // recursively trigger `toJSON` for Realm instances with the same cache. + result[key] = (value instanceof realmConstructor.Object || value instanceof realmConstructor.Collection) + ? value.toJSON(key, cache) + : value; }); return result;