Migrating code that uses Manifest (to Scala3)

jackson-module-scala has a lot of test code that uses Scala 2 Manifest passing to act as a convenient way to get the Java class. I can change the code to pass the Java class explicitly but there is a lot of code to change.

Would anyone have any suggestions how this code be rewritten to support Scala 3.

  def deserialize[T: Manifest](value: String) : T =
    newMapper.readValue(value, typeReference[T])

  def typeReference[T: Manifest]: TypeReference[T] = new TypeReference[T] {
    override def getType: Type = typeFromManifest(manifest[T])
  }

If it’s only about getting the Java class, could you perhaps use a ClassTag instead? That should still be supported if I’m not mistaken. It’s a weaker version of Manifest that is restricted to erased java types.

Thanks Jasper. As I dig into this more, it looks like in many cases, the mainfest is also used to get wrapped type for reference types like Either[L, R].

The code that I will need to get working without Manifest support is:

That’s a bigger problem. Then you might have to use izumi-reflect which provides a portable TypeTag alternative. Or write your own specialized macro to extract at compile time whatever type information your need at runtime.