Extracting case classes with Type Parameters fails with runtime error
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 324
- Avg merge
- 4h 35m
- Merged PRs (30d)
- 30
Description
Not sure if there is an issue on this, but currently you are unable to automatically extract case classes if they have type constructors, more detail is in the scala REPL below.
Is this an intended limitation, or is it a case of a feature not being supported yet?
Scala version is 2.11.1
import spire.math._
scala> case class Test(a:Natural)
defined class Test
scala> val a = Test(Natural(2))
a: Test = Test(2)
scala> Extraction.decompose(a)
res2: org.json4s.JValue = JObject(List((a,JInt(2))))
scala> case class Test2[T <% Number](b:T)
defined class Test2
scala> val b = Test2(Natural(3))
b: Test2[spire.math.Natural] = Test2(3)
scala> Extraction.decompose(b)
org.json4s.package$MappingException: Can't find constructor for Test2
at org.json4s.reflect.ScalaSigReader$.readConstructor(ScalaSigReader.scala:21)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder.ctorParamType(Reflector.scala:90)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder$$anonfun$constructorsAndCompanion$3$$anonfun$13.apply(Reflector.scala:148)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder$$anonfun$constructorsAndCompanion$3$$anonfun$13.apply(Reflector.scala:122)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder$$anonfun$constructorsAndCompanion$3.apply(Reflector.scala:122)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder$$anonfun$constructorsAndCompanion$3.apply(Reflector.scala:116)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:35)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder.constructorsAndCompanion(Reflector.scala:116)
at org.json4s.reflect.Reflector$ClassDescriptorBuilder.result(Reflector.scala:156)
at org.json4s.reflect.Reflector$.createDescriptor(Reflector.scala:50)
at org.json4s.reflect.Reflector$$anonfun$describe$1.apply(Reflector.scala:44)
at org.json4s.reflect.Reflector$$anonfun$describe$1.apply(Reflector.scala:44)
at org.json4s.reflect.package$Memo.apply(package.scala:39)
at org.json4s.reflect.Reflector$.describe(Reflector.scala:44)
at org.json4s.Extraction$.decomposeObject$1(Extraction.scala:91)
at org.json4s.Extraction$.internalDecomposeWithBuilder(Extraction.scala:180)
at org.json4s.Extraction$.decomposeWithBuilder(Extraction.scala:67)
at org.json4s.Extraction$.decompose(Extraction.scala:194)```
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
Reproduce the Scala 2.11.1 REPL example, comparing extraction of Test with parameterized Test2. Start with reflect/ScalaSigReader.scala:21 and reflect/Reflector.scala, where the stack trace reports constructor discovery. Done means parameterized case classes no longer fail with MappingException during Extraction.decompose, with regression coverage for the reported example.
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
- Needs clarification
- Newbie friendliness
- 30/100