json4s / json4s/json4s

Extraction.decompose fails on case class with secondary implicit arguments list : org.json4s.package$MappingException: Can't find constructor

Open
#702 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

json4s version

3.6.9

scala version

2.13.3

jdk version

11.0.7

Extraction.decompose successes with :

case class CheckedValue[NUM](
  value: NUM,
  isPrime: Boolean,
  digitCount: Long,
  nth: NUM)

Extraction.decompose fails with :

case class CheckedValue[NUM](
  value: NUM,
  isPrime: Boolean,
  digitCount: Long,
  nth: NUM)(implicit numops: Integral[NUM])

Raised exception :

- should be possible to serialize / deserialize complex types with implicits *** FAILED ***
  org.json4s.package$MappingException: Can't find constructor for CheckedValue
  at org.json4s.reflect.package$.fail(package.scala:95)
  at org.json4s.reflect.ScalaSigReader$.$anonfun$readConstructor$3(ScalaSigReader.scala:26)
  at scala.Option.getOrElse(Option.scala:201)
  at org.json4s.reflect.ScalaSigReader$.readConstructor(ScalaSigReader.scala:26)
  at org.json4s.reflect.Reflector$ClassDescriptorBuilder.ctorParamType(Reflector.scala:93)
  at org.json4s.reflect.Reflector$ClassDescriptorBuilder.$anonfun$createConstructorDescriptors$7(Reflector.scala:182)
  at scala.collection.immutable.ArraySeq.$anonfun$map$1(ArraySeq.scala:71)
  at scala.collection.immutable.ArraySeq.$anonfun$map$1$adapted(ArraySeq.scala:71)
  at scala.collection.immutable.ArraySeq$.tabulate(ArraySeq.scala:192)
  at scala.collection.immutable.ArraySeq$.tabulate(ArraySeq.scala:171)

test snippet :

    import org.json4s.native.Serialization.write
    import org.json4s.DefaultFormats
    import org.json4s.Extraction, Extraction.decompose
    implicit val formats = DefaultFormats
    val something1 = CheckedValue(value=7L, isPrime=true, digitCount=1, nth=4)
    val jvalue = decompose(something1)
    write(jvalue) shouldBe """{"value":7,"isPrime":true,"digitCount":1,"nth":4}"""

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

Reproduce the failure with the CheckedValue case class and test snippet in the issue, then read ScalaSigReader.scala around line 26 and Reflector.scala around lines 93 and 182. Done means Extraction.decompose handles the secondary implicit argument list and the shown write assertion produces the expected JSON without a MappingException.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.