I ran into a run time exception while serializing a case class, which extends a trait, which in turn extends another grandparent trait.
Problem occurs only when the grandparent trait contains a val or lazy val, which is a tuple.
trait Trait0 {
def a: Int
lazy val b: (Int, Int) = (1, 2)
// also errors if "val"
// executes if "def" or just a simple type
}
trait Trait1 extends Trait0
case class Test(a: Int) extends Trait1
object Main {
def main(args: Array[String]): Unit = {
import org.json4s._
import org.json4s.native.Serialization.write
implicit val formats = DefaultFormats
println(write(Test(1)))
}
}
RunTime Exception I get is
Exception in thread "main" org.json4s.package$MappingException: Can't find field b from class com.adobe.formfactory.generator.Test at org.json4s.reflect.package$.fail(package.scala:95) at org.json4s.reflect.ScalaSigReader$.read$1(ScalaSigReader.scala:43) at org.json4s.reflect.ScalaSigReader$.$anonfun$readField$3(ScalaSigReader.scala:47) at scala.Option.getOrElse(Option.scala:121) at org.json4s.reflect.ScalaSigReader$.read$1(ScalaSigReader.scala:47) at org.json4s.reflect.ScalaSigReader$.readField(ScalaSigReader.scala:49) at org.json4s.reflect.Reflector$ClassDescriptorBuilder.$anonfun$fields$3(Reflector.scala:69) at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234) at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59) at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52) at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) at scala.collection.TraversableLike.map(TraversableLike.scala:234) at scala.collection.TraversableLike.map$(TraversableLike.scala:227) at scala.collection.AbstractTraversable.map(Traversable.scala:104) at org.json4s.reflect.Reflector$ClassDescriptorBuilder.fields(Reflector.scala:68) at org.json4s.reflect.Reflector$ClassDescriptorBuilder.properties(Reflector.scala:85) at org.json4s.reflect.Reflector$ClassDescriptorBuilder.result(Reflector.scala:184) at org.json4s.reflect.Reflector$.createDescriptor(Reflector.scala:53) at org.json4s.reflect.Reflector$.$anonfun$describe$1(Reflector.scala:48) at org.json4s.reflect.package$Memo.apply(package.scala:36) at org.json4s.reflect.Reflector$.describe(Reflector.scala:48) at org.json4s.Extraction$.decomposeObject$1(Extraction.scala:118) at org.json4s.Extraction$.internalDecomposeWithBuilder(Extraction.scala:228) at org.json4s.Extraction$.decomposeWithBuilder(Extraction.scala:64) at org.json4s.native.Serialization$.write(Serialization.scala:43) at org.json4s.native.Serialization$.write(Serialization.scala:37) at com.adobe.formfactory.generator.Main$.main(Main.scala:31) at com.adobe.formfactory.generator.Main.main(Main.scala)
Scala2.12.3
JDK1.8
json4s-native 3.5.3
I am guessing json4s isn't traversing up the super chain for tuples or other composite objects ?
If it were a case of providing custom serializer, the error, would mention that certain type cant be serialized.
I guess this is an existing bug since v3.4