1

I'm using Jerkson, and I need to check if a given class can be serialized. The java version just needs a class, but jerkson does this:

 def canSerialize[A](implicit mf: Manifest[A]) = mapper.canSerialize(mf.erasure)

Given that I have an instance, how can I call this? I pretty much tried

canSerialize[ClassManifest.fromClass(foo)]

But its not working. I wonder why the guys at jerkson could not make it simpler by just making this: canSerialize(Class[_]) ...

Any ideas on how can I invoke this?

Edit:

I fixed this by using:

canSerilialize(Manifest.classType(foo.getClass))
Vinicius Carvalho
  • 3,994
  • 4
  • 23
  • 29
  • Adding more context: If I try to use the canSerialize(ClassManifest.fromClass(foo)) I get the following: type mismatch; found : scala.reflect.ClassManifest[?0] where type ?0 <: com.acme.domain.Foo required: Manifest[?] – Vinicius Carvalho Mar 25 '12 at 15:18

2 Answers2

3

How about this:

canSerialize[Foo]

Compiler can automatically generate manifest for you (if it has enough type information in context)

Since Scala 2.8.0 canSerialize can be written via context bound. See more

Community
  • 1
  • 1
Sergey Passichenko
  • 6,920
  • 1
  • 28
  • 29
0

If you don't know the class in advance, you can always pass the manifest as a parameter, i.e. this should work: canSerialize( Manifest.classType( foo.getClass ) ).

Tomer Gabel
  • 4,104
  • 1
  • 33
  • 37