I’m getting an `InvocationTargetException` due to ...
# serialization
r
I’m getting an 
InvocationTargetException
 due to a 
NoClassDefFoundError
 when trying to invoke the serializer() method on a 
@Serializable
 class.  The class and method are found (via reflection using Ktor’s kotlinx.serialization content negotiation feature) and set accessible, but this still happens.  The annotated data class is public, but in a dependent module from the actual server that is executed. Any idea what might be wrong?
s
Can you provide a full stack trace? Are you using the built-in Ktor kotlinx.serialization Serializer? EDIT: Nvm realized you’re talking about server-side serialization.
r
I am using the built-in kotlinx.serialization plugin.
i’ll get a full stack trace
s
My original comment stands though re: client side. The client serializer for kotlinx.serialization really needs updates. I wouldn’t be surprised if the same was true for the server.
r
Unfortunately I’ve been doing a little digging so don’t have that full stack trace, but I’m testing with some samples and I think I see the underlying cause of the reflected invoke failing, though I don’t know why it’s happening.
Copy code
val jsonString = json.stringify(
      CreateRecordRequest.serializer(),
      CreateRecordRequest(
        filename = "foo",
        content_type = "image/png",
        byte_size = 123,
        checksum = "12345abcde"
      )
    )
Here’s my test case
For this class:
Copy code
@Serializable
data class CreateRecordRequest(
  val filename: String,
  val content_type: String,
  val byte_size: Int,
  val checksum: String
)
Which fails with this:
Copy code
java.lang.NoSuchMethodError: 'void kotlinx.serialization.internal.SerialClassDescImpl.<init>(java.lang.String, kotlinx.serialization.internal.GeneratedSerializer, int)'
	at com.pixite.pigment.cms.storage.CreateRecordRequest$$serializer.<clinit>(Api.kt:39)
	at com.pixite.pigment.cms.storage.CreateRecordRequest$Companion.serializer(Api.kt)
(boy, the thread UI isn’t great for this 🙁)
s
You can attach the snippets which makes it a bit easier to expand the code without the wrapping instead of using code blocks.
🙏 1
r
Here’s the relevant stack trace. Under this is all test framework stuff
s
Definitely weird, never seen that error myself. Just to eliminate obvious sources of error, you have the serialization runtime on your classpath?
r
Anyway, looks like it’s not a ktor issue. I can’t seem to use that serializer either direction.
s
I don’t see any reason why this
CreateRecordRequest.serializer()
shouldn’t just work. Seems like that’s probably where it’s failing.
r
I do. It’s both an implementation dependency of this module and an implementation dependency of the server module
this code is in a different module than the server, so I wonder if the generated bits aren’t being included in the server’s runtime classpath?
s
The generated code lives in a companion of the serializable so not sure that would be a problem.
r
but the code that executes the serialization is within the module where it’s defined.
s
What version of Kotlin are you using, what version of the runtime?
The runtimes are tightly coupled to the kotlin version, so I’d verify you have a working combination of both
r
Was just looking at that. 1.3.71 and 0.14.0
s
Yeah I’d downgrade to 1.3.70 and upgrade to 0.20.0
That’s the current working combination. It might work with 1.3.71 but I think 0.20.0 is only guaranteed to support 70
FWIW I just checked a project with 1.3.70 and 0.20.0 and
kotlinx.serialization.internal.SerialClassDescImpl
is resolvable.
r
0.14.0 will definitely not work with 1.3.7x
r
alright, dropping kotlin and bumping serialization and ktor does the trick. Thanks, guys!
👍 1