mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Change DelegateKey to use AnnotationSpec instead of AnnotationMirror
AnnotationSpec implements equals() in the way we need, but AnnotationMirror doesn't. As a consequence this fixes a problem where we were generating redundant adapters. Closes: https://github.com/square/moshi/issues/563
This commit is contained in:
@@ -32,6 +32,7 @@ import org.junit.Assert.fail
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.util.Locale
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
||||
class GeneratedAdaptersTest {
|
||||
|
||||
@@ -857,6 +858,28 @@ class GeneratedAdaptersTest {
|
||||
throw AssertionError()
|
||||
}
|
||||
|
||||
/** https://github.com/square/moshi/issues/563 */
|
||||
@Test fun qualifiedAdaptersAreShared() {
|
||||
val moshi = Moshi.Builder()
|
||||
.add(UppercaseJsonAdapter())
|
||||
.build()
|
||||
val jsonAdapter = moshi.adapter(MultiplePropertiesShareAdapter::class.java)
|
||||
|
||||
val encoded = MultiplePropertiesShareAdapter("Android", "Banana")
|
||||
assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":"ANDROID","b":"BANANA"}""")
|
||||
|
||||
val delegateAdapters = jsonAdapter::class.memberProperties.filter {
|
||||
it.returnType.classifier == JsonAdapter::class
|
||||
}
|
||||
assertThat(delegateAdapters).hasSize(1)
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class MultiplePropertiesShareAdapter(
|
||||
@Uppercase(true) var a: String,
|
||||
@Uppercase(true) var b: String
|
||||
)
|
||||
|
||||
@Test fun toJsonOnly() {
|
||||
val moshi = Moshi.Builder()
|
||||
.add(CustomToJsonOnlyAdapter())
|
||||
|
Reference in New Issue
Block a user