mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Change the Kotlin reflection adapter to yield to the codegen adapter
This commit is contained in:
@@ -17,6 +17,7 @@ package com.squareup.moshi.kotlin.reflect
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.squareup.moshi.JsonDataException
|
||||
import com.squareup.moshi.JsonQualifier
|
||||
import com.squareup.moshi.Moshi
|
||||
@@ -840,6 +841,25 @@ class KotlinJsonAdapterTest {
|
||||
assertThat(adapter.toJson(value)).isEqualTo(json)
|
||||
}
|
||||
|
||||
@Test fun mixingReflectionAndCodegen() {
|
||||
val moshi = Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()
|
||||
val generatedAdapter = moshi.adapter(UsesGeneratedAdapter::class.java)
|
||||
val reflectionAdapter = moshi.adapter(UsesReflectionAdapter::class.java)
|
||||
|
||||
assertThat(generatedAdapter.javaClass.name)
|
||||
.contains("KotlinJsonAdapterTest_UsesGeneratedAdapterJsonAdapter")
|
||||
assertThat(reflectionAdapter.javaClass.name)
|
||||
.doesNotContain("KotlinJsonAdapterTest_UsesReflectionAdapterJsonAdapter")
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class UsesGeneratedAdapter(var a: Int, var b: Int)
|
||||
|
||||
@JsonClass(generateAdapter = false)
|
||||
class UsesReflectionAdapter(var a: Int, var b: Int)
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@JsonQualifier
|
||||
annotation class Uppercase
|
||||
|
Reference in New Issue
Block a user