feat(hashmap): add FromJson impl for HashMap[String, V] to match Map#3584
Open
bobzhang wants to merge 1 commit into
Open
feat(hashmap): add FromJson impl for HashMap[String, V] to match Map#3584bobzhang wants to merge 1 commit into
bobzhang wants to merge 1 commit into
Conversation
Ports impl FromJson for Map[String, V] (from json/from_json.mbt) to HashMap. Uses the public @json.JsonPath.add_key API for path tracking. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collaborator
Coverage Report for CI Build 4336Coverage decreased (-0.005%) to 94.288%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds JSON deserialization support for HashMap[String, V] to align HashMap’s API with the existing Map[String, V] FromJson implementation in moonbitlang/core/json.
Changes:
- Added
impl @json.FromJson for HashMap[String, V]inhashmap/json.mbt. - Added
moonbitlang/core/jsonas a non-test dependency for thehashmappackage. - Updated generated package interface metadata (
pkg.generated.mbti) to reflect the new import and impl.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| hashmap/json.mbt | Implements @json.FromJson for HashMap[String, V] and documents usage. |
| hashmap/moon.pkg | Adds moonbitlang/core/json to non-test imports so the new impl can compile/use @json. |
| hashmap/pkg.generated.mbti | Regenerates package interface to include the new json import and FromJson impl. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| guard json is Object(obj) else { | ||
| raise @json.JsonDecodeError((path, "HashMap::from_json: expected object")) | ||
| } | ||
| let res : HashMap[String, V] = HashMap([]) |
Comment on lines
+44
to
+50
| pub impl[V : @json.FromJson] @json.FromJson for HashMap[String, V] with from_json( | ||
| json, | ||
| path, | ||
| ) { | ||
| guard json is Object(obj) else { | ||
| raise @json.JsonDecodeError((path, "HashMap::from_json: expected object")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
impl FromJson for HashMap[String, V]to mirror the same impl thatMap[String, V]already has injson/from_json.mbt.Motivation
MapandHashMapshould have a consistent API.HashMapwas missing JSON deserialization support.Changes
impl @json.FromJson for HashMap[String, V]inhashmap/json.mbtmoonbitlang/core/jsonas a non-test import inhashmap/moon.pkgJsonPath::add_keyAPI (enum variants are private)pkg.generated.mbti