Pattern matching is order-dependent
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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