Recognising Scala 3 classes

Jackson-Module-Scala uses the ScalaSignature and ScalaLongSignature annotations that are added to scala 2.x compiled classes.

Scala 3 no longer does this. Is there any other good way to spot Scala-compiled classes as opposed to Java-compiled classes?
One approach might be to check for the .tasty file that acts as a companion to the class but this may not be the most performant approach.

Relates to

Any pointers would be appreciated.

What an interesting issue. Do you know how and why Jackson treats classes compiled from scala different from classes compiled from java?

Anyway, does javap maybe give you any leads on whether you can find anything in the class file?

I did decompile some classes from https://github.com/scala/scala3-example-project using the IntelliJ decompiler and there wasn’t anything obvious.

Other than the presence of the .tasty files and the fact that many Scala compiled classes would be subclasses of scala-lang classes like Product, Function1, etc.

According to this code comment:

To understand the situation, it’s helpful to know that:

  • Scalac emits the ScalaSig attribute for classfiles with pickled information
    and the Scala attribute for everything else.
  • Dotty emits the TASTY attribute for classfiles with pickled information
    and the Scala attribute for every classfile.

Therefore, if the Scala attribute is present but the TASTY
attribute isn’t, this classfile is a compilation artifact.

So every scala classfile should at least contain the “scala” attribute. However I don’t think you can easily get classfile attributes from a regular Class object.