问题
Didn't find the answer in these topics: first, second
Have the next problem. I have a case class named Foo:
case class Foo(a: Int, b: List[Int])
When I need to make an AST of this class I invoke Extraction.decompose(<instance of Foo>)
and get an AST represenation of foo instance.
But if I make field b
as private
case class Foo(a: Int, private val b: List[Int])
I get org.json4s.package$MappingException: Can't find ScalaSig for class java.lang.Object
exception.
This is only true for private fields that are collections.
If private field is simple object it simply doesn't get appeared in AST. Why this exception does happen?
EDIT The same exception arises if I have a case class extending some trait with val or lazy val fields:
trait Bar {
val list: List[Int] = List(1,2,3)
}
case class Example(field: Double) extends Bar
回答1:
I think that this is the similar to the issue that I'm running into.
First, ScalaSigreader#42
if (current == null)
should be
if (current == classOf[java.lang.Object])
Then, you'll get a more helpful error message: "Can't find field b from Foo". But this by itself doesn't fix the issue.
I haven't looked into a fix for the private field issue. However, I do have a fix for the issue with the interface. For that problem, ScalaSigReader#45 needs to be modified.
Currently if the field isn't found then the superclass is searched:
findField(findClass(current), name).getOrElse(read(current.getSuperclass))
The interfaces must be searched as well:
findField(current, name)
.orElse(current.getInterfaces.flatMap(findField(_, name)).headOption)
.getOrElse(read(current.getSuperclass))
private def findField(clazz: Class[_], name: String): Option[MethodSymbol] =
findField(findClass(clazz), name)
See also:
Issue #403
Pull #436
来源:https://stackoverflow.com/questions/36143776/cant-find-scalasig-for-class-java-lang-object