extractOpt[String] seems to be broken in 3.6.x
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 324
- Avg merge
- 4h 35m
- Merged PRs (30d)
- 30
Description
json4s 3.6.7
scala version 2.12.10
jdk version 1.8.0_92
In 3.5.x I could do:
val extractedOptionalField = (myJsonObject \ "myOptionalField").extractOpt[String]
Which worked, and produced None when "myOptionalField" is not present in the object.
For some reason this does not work in 3.6.x when the field is missing (throws org.json4s.package$MappingException: Did not find value which can be converted into java.lang.String). As a workaround I found that i can use extract[Option[String]] and it works as expected. But I do not understand what is the point of extractOpt if it throws an exception in case the field is missing? What is the reason the behavior changed? For me it seems broken.
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 reported Scala expressions with json4s 3.6.7, Scala 2.12.10, and the missing "myOptionalField" case. Compare extractOpt[String] with extract[Option[String]] and the 3.5.x behavior; done means the intended missing-field behavior is established and covered by a regression test.
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
- 42/100