title: Moshi 1.9.x Cannot serialize Kotlin type
body: <p>I'm running into the following crash and stack trace after upgrading to <a href="https://github.com/square/moshi/blob/master/CHANGELOG.md#version-191" rel="noreferrer">Moshi 1.9.1</a> (from <a href="https://github.com/square/moshi/blob/master/CHANGELOG.md#version-180" rel="noreferrer">1.8.0</a>):</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.garpr.android.data.models.RankedPlayer. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.
  for class com.garpr.android.data.models.RankedPlayer
  for class com.garpr.android.data.models.AbsPlayer
  
      at com.squareup.moshi.Moshi$LookupChain.exceptionWithLookupStack(Moshi.java:349)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:150)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:98)
      at com.squareup.moshi.AdapterMethodsFactory$AdapterMethod.bind(AdapterMethodsFactory.java:313)
      at com.squareup.moshi.AdapterMethodsFactory.create(AdapterMethodsFactory.java:62)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:138)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:98)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:72)
      at com.garpr.android.data.converters.AbsPlayerConverterTest.setUp(AbsPlayerConverterTest.kt:76)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:546)
      at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:252)
      at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.garpr.android.data.models.RankedPlayer. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.
      at com.squareup.moshi.ClassJsonAdapter$1.create(ClassJsonAdapter.java:83)
      at com.squareup.moshi.Moshi.nextAdapter(Moshi.java:169)
      at com.squareup.moshi.AdapterMethodsFactory$AdapterMethod.bind(AdapterMethodsFactory.java:312)
      at com.squareup.moshi.AdapterMethodsFactory.create(AdapterMethodsFactory.java:62)
      at com.squareup.moshi.Moshi.adapter(Moshi.java:138)
      ... 23 more
  </code></pre>
  
  <p>I saw <a href="https://stackoverflow.com/questions/58660364/moshi-1-9-1-cannot-serialize-kotlin-type">this other Stack Overflow answer</a>, but it does not apply to me, as I've already added the relevant <code>@JsonClass(generateAdapter = X)</code> line to my classes.</p>
  
  <p>I use a custom <a href="https://github.com/charlesmadere/smash-ranks-android/blob/e7cd6e8d5ea80984b69701d50456ab11376cd2aa/smash-ranks-android/app/src/main/java/com/garpr/android/data/converters/AbsPlayerConverter.kt" rel="noreferrer"><code>AbsPlayerConverter</code> class</a> for my <a href="https://github.com/charlesmadere/smash-ranks-android/blob/e7cd6e8d5ea80984b69701d50456ab11376cd2aa/smash-ranks-android/app/src/main/java/com/garpr/android/data/models/AbsPlayer.kt" rel="noreferrer"><code>AbsPlayer</code></a> class, this is used so that I can determine which subclass to resolve to. And then, if it resolves to <a href="https://github.com/charlesmadere/smash-ranks-android/blob/a66d118f33c23b7a655d10da21630f909abd3639/smash-ranks-android/app/src/main/java/com/garpr/android/data/models/RankedPlayer.kt" rel="noreferrer"><code>RankedPlayer</code></a>, I use another custom converter for that (<a href="https://github.com/charlesmadere/smash-ranks-android/blob/a66d118f33c23b7a655d10da21630f909abd3639/smash-ranks-android/app/src/main/java/com/garpr/android/data/converters/RankedPlayerConverter.kt" rel="noreferrer"><code>RankedPlayerConverter</code></a>).</p>
  
  <p>Here is <a href="https://github.com/charlesmadere/smash-ranks-android/blob/a66d118f33c23b7a655d10da21630f909abd3639/smash-ranks-android/app/src/main/java/com/garpr/android/koin/MiscModule.kt#L26" rel="noreferrer">my Moshi-builder code</a>:</p>
  
  <pre><code>Moshi.Builder()
          .add(AbsPlayerConverter)
          .add(AbsRegionConverter)
          .add(AbsTournamentConverter)
          .add(MatchConverter)
          .add(RankedPlayerConverter)
          .add(SimpleDateConverter)
          .build()
  </code></pre>
  
  <p>And here is Moshi in <a href="https://github.com/charlesmadere/smash-ranks-android/blob/6a01556c71f17cc74c2f3c93d8c6b331535b20d1/smash-ranks-android/app/build.gradle#L131" rel="noreferrer">my gradle file</a>:</p>
  
  <pre><code>implementation "com.squareup.moshi:moshi:1.9.1"
  kapt "com.squareup.moshi:moshi-kotlin-codegen:1.9.1"
  </code></pre>
  
  <p>So finally, after all of that text and info, I have no idea how I can be running into this crash. I clearly have defined how to serialize/deserialize my <code>RankedPlayer</code> class. And if I downgrade to Moshi 1.8.0, and leave my codebase completely as-is, this crash goes away and everything works flawlessly.</p>
  
  <p>Anyone have any ideas?</p>
  
  <p>Thanks!!</p>