Skip to content

feat(hashmap): add FromJson impl for HashMap[String, V] to match Map#3584

Open
bobzhang wants to merge 1 commit into
mainfrom
feat/hashmap-fromjson
Open

feat(hashmap): add FromJson impl for HashMap[String, V] to match Map#3584
bobzhang wants to merge 1 commit into
mainfrom
feat/hashmap-fromjson

Conversation

@bobzhang

Copy link
Copy Markdown
Contributor

Summary

Adds impl FromJson for HashMap[String, V] to mirror the same impl that Map[String, V] already has in json/from_json.mbt.

Motivation

Map and HashMap should have a consistent API. HashMap was missing JSON deserialization support.

Changes

  • Added impl @json.FromJson for HashMap[String, V] in hashmap/json.mbt
  • Added moonbitlang/core/json as a non-test import in hashmap/moon.pkg
  • Uses the public JsonPath::add_key API (enum variants are private)
  • Updated pkg.generated.mbti

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>
Copilot AI review requested due to automatic review settings May 13, 2026 09:11
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 4336

Coverage decreased (-0.005%) to 94.288%

Details

  • Coverage decreased (-0.005%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (3 of 4 lines covered, 75.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
hashmap/json.mbt 4 3 75.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15791
Covered Lines: 14889
Line Coverage: 94.29%
Coverage Strength: 217478.57 hits per line

💛 - Coveralls

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

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] in hashmap/json.mbt.
  • Added moonbitlang/core/json as a non-test dependency for the hashmap package.
  • 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.

Comment thread hashmap/json.mbt
guard json is Object(obj) else {
raise @json.JsonDecodeError((path, "HashMap::from_json: expected object"))
}
let res : HashMap[String, V] = HashMap([])
Comment thread hashmap/json.mbt
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"))
}
@bobzhang bobzhang enabled auto-merge (squash) May 13, 2026 09:32
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.

3 participants