Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes toJSON() for Struct to correctly return a dom.Value instance #752

Merged
merged 1 commit into from Mar 30, 2023

Conversation

desaikd
Copy link
Contributor

@desaikd desaikd commented Mar 30, 2023

Issue #751

Description of changes:

This PR works on fixing toJSON() for Struct to correctly return a dom.Value instance.

Solution:

  • JSON.stringify() uses toJSON() if the object has that defined as per MDN:

If the value has a toJSON() method, it's responsible to define what data will be serialized. Instead of the object being serialized, the value returned by the toJSON() method when called will be serialized.

  • Previously the toJSON() for struct was returning an object based on null object prototype which was giving incorrect results for instanceof when called inside the JSON.stringify replacer function.
  • Now we are using Struct's prototype to for the return object on toSJON().

List of changes:

  • Struct#toJSON() now creates an object based on Struct's prototype instead of null object's prototype.

Tests:

added a unit test to check for instanceof dom.Value inside JSON.stringify replacer function.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* `Struct#toJSON()` now creates an object based on Struct's prototype
instead of null object's prototype.
@desaikd desaikd requested a review from zslayton March 30, 2023 18:52
Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@desaikd desaikd merged commit f83fcf0 into amazon-ion:master Mar 30, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants