json4s / json4s/json4s

Pattern matching is order-dependent

Open
#113 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
324
Avg merge
4h 35m
Merged PRs (30d)
30

Description

This is particularly bothersome when writing custom serializers. (Note the different order of the fields in each call to parse)

scala> val JObject(JField("test", JDouble(x)) :: JField("two", JString(s)) :: Nil)
     |   = parse("""{"test":3.0,"two":"three"}""")
x: Double = 3.0
s: String = three

scala> val JObject(JField("test", JDouble(x)) :: JField("two", JString(s)) :: Nil)
     |   = parse("""{"two":"three","test":3.0}""")
scala.MatchError: JObject(List((two,JString(three)), (test,JDouble(3.0))))
(of class org.json4s.JsonAST$JObject)
[...]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two parse examples in the issue and trace how JObject is matched against the field patterns. Confirm the behavior with an order-swapped object, then make the demonstrated destructuring work regardless of JSON field order and verify both examples succeed.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.