Skip to content

Conversation

nbauernfeind
Copy link

I'm using jackson-module-scala which uses scalabeans under the covers. I want to serialize a class that looks like this:

class Metrics {
  outer =>
  val numThingA = new Counter(...)
  val numThingB  = new Counter(...)
  val currThingC = new AtomicReference(...)
  // ... etc you get the point

  def newSnapshot = new Snapshot  
  case class Snapshot (
    numThingA: Long = outer.numThingA.count,
    numThingB: Long = outer.numThingB.count,
    currThingC: C = outer.currThingC.get
  )
}

In the end I stick the snapshot into a case class:

case class DataResponse(..., metrics: Metrics#Snapshot)

But it fails to serialize the snapshot with this exception:

scala.MatchError: org.scalastuff.scalabeans.sig.OuterTestClass (of class org.scalastuff.scalabeans.sig.ClassDeclExtractor$$anonfun$13$$anon$10)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler.getTypeDecl$1(ScalaTypeCompiler.scala:155)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler.resolveScalaType(ScalaTypeCompiler.scala:167)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$$anonfun$3.apply(ScalaTypeCompiler.scala:146)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$$anonfun$3.apply(ScalaTypeCompiler.scala:145)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:60)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)
    at scala.collection.mutable.ArrayBuffer.map(ArrayBuffer.scala:47)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler.compile(ScalaTypeCompiler.scala:145)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$$anonfun$1$$anonfun$apply$2.apply(ScalaTypeCompiler.scala:51)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$$anonfun$1$$anonfun$apply$2.apply(ScalaTypeCompiler.scala:48)
    at scala.Option$WithFilter.map(Option.scala:174)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$$anonfun$1.apply(ScalaTypeCompiler.scala:48)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$$anonfun$1.apply(ScalaTypeCompiler.scala:47)
    at scala.Option.flatMap(Option.scala:146)
    at org.scalastuff.scalabeans.sig.ScalaTypeCompiler$.classInfoOf(ScalaTypeCompiler.scala:47)
...

So, here's a fix... and it works. Test fails beforehand but required the helper classes to be at the top level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant