Skip to content

Conversation

@zsilbi
Copy link
Collaborator

@zsilbi zsilbi commented Mar 3, 2025

Currently the serializer can only handle object returns from input.toJSON():

class TestString {
  toJSON() {
    return "value";
  }
}
serialize(new TestString()); // Error: Cannot serialize String

There is no rule that toJSON() must return an object type.

For example:

typeof new Date().toJSON(); // string

I added a fix that keeps the current output format for objects, but uses TestString('value') format for others.

@codecov
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.76%. Comparing base (c5173ba) to head (75baaa0).
Report is 88 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #135       +/-   ##
===========================================
+ Coverage   80.31%   95.76%   +15.44%     
===========================================
  Files           8        8               
  Lines        1006      472      -534     
  Branches      111      123       +12     
===========================================
- Hits          808      452      -356     
+ Misses        198       18      -180     
- Partials        0        2        +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Co-authored-by: Pooya Parsa <[email protected]>
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thnx!

@pi0 pi0 merged commit 6968b45 into unjs:main Mar 4, 2025
4 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.

2 participants