Skip to content

Add JSON marshal/unmarshal support - #22

Merged
ghosind merged 3 commits into
mainfrom
feat/json
Nov 21, 2025
Merged

Add JSON marshal/unmarshal support#22
ghosind merged 3 commits into
mainfrom
feat/json

Conversation

@ghosind

@ghosind ghosind commented Nov 21, 2025

Copy link
Copy Markdown
Owner

For #18, this PR adds MarshalJSON and UnmarshalJSON methods for the collections and dictionaries.

There are two ways to marshal/unmarshal the types to JSON:

  • Invoke the MarshalJSON / UnmarshalJSON:
s := set.NewHashSet[int]()
b, err := s.MarshalJSON()
  • Use json.Marshal/json.Unmarshal:
s := set.NewHashSet[int]()
b, err := json.Marshal(s)

Signed-off-by: Chen Su <ghosind@gmail.com>
Signed-off-by: Chen Su <ghosind@gmail.com>
@ghosind ghosind added this to the v0.5.0 milestone Nov 21, 2025
@ghosind
ghosind requested a review from Copilot November 21, 2025 08:10
@ghosind ghosind added the enhancement New feature or request label Nov 21, 2025
@codecov

codecov Bot commented Nov 21, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.55556% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.04%. Comparing base (9743c82) to head (767c48b).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
dict/sync_dict.go 75.00% 3 Missing and 3 partials ⚠️
list/linked_list.go 57.14% 4 Missing and 2 partials ⚠️
dict/hash_dict.go 75.00% 1 Missing and 1 partial ⚠️
list/array_list.go 75.00% 1 Missing and 1 partial ⚠️
list/copy_on_write_array_list.go 81.81% 1 Missing and 1 partial ⚠️
set/hash_set.go 80.00% 1 Missing and 1 partial ⚠️
set/sync_set.go 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
- Coverage   94.20%   93.04%   -1.16%     
==========================================
  Files          21       21              
  Lines        1725     1539     -186     
==========================================
- Hits         1625     1432     -193     
+ Misses         73       70       -3     
- Partials       27       37      +10     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds JSON marshaling and unmarshaling support to all collection and dictionary types by implementing MarshalJSON and UnmarshalJSON methods. The changes enable both direct method calls and usage with the standard json.Marshal/json.Unmarshal functions.

Key changes:

  • Added JSONMarshaler and JSONUnmarshaler interface definitions to the core Collection and Dict interfaces
  • Implemented JSON serialization for all set, list, and dictionary types (sets/lists as arrays, dicts as objects)
  • Added comprehensive test coverage for JSON operations across all implementations
  • Refactored test helper type names for consistency (e.g., setTestConstructorsetConstructor)

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
encoding.go Defines JSONMarshaler and JSONUnmarshaler interface aliases
collection.go Adds JSON interface requirements to Collection interface
dict.go Adds JSON interface requirements to Dict interface
set/hash_set.go Implements MarshalJSON/UnmarshalJSON for HashSet
set/sync_set.go Implements MarshalJSON/UnmarshalJSON for thread-safe SyncSet
list/array_list.go Implements MarshalJSON/UnmarshalJSON for ArrayList
list/linked_list.go Implements MarshalJSON/UnmarshalJSON for LinkedList with zero-value handling
list/copy_on_write_array_list.go Implements MarshalJSON/UnmarshalJSON for CopyOnWriteArrayList
dict/hash_dict.go Implements MarshalJSON/UnmarshalJSON for HashDict
dict/sync_dict.go Implements MarshalJSON/UnmarshalJSON for thread-safe SyncDict
set/set_test.go Adds testSetJSON and consolidates test helpers; renames constructor type
set/hash_set_test.go Removes redundant test calls (moved to common testSet)
set/sync_set_test.go Removes redundant test calls (moved to common testSet)
set/set_go123_test.go Updates function signature to use renamed constructor type
list/list_test.go Adds testListJSON for JSON operations testing
dict/dict_test.go Adds testDictJSON and renames constructor type for consistency
dict/dict_go123_test.go Updates function signatures to use renamed constructor type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dict/sync_dict.go
Comment thread set/sync_set.go
Comment thread dict/sync_dict.go
Signed-off-by: Chen Su <ghosind@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ghosind
ghosind merged commit a4184b5 into main Nov 21, 2025
28 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants