ansman/kotshi

Multiple classes found with annotations KotshiJsonAdapterFactory

feiflying opened this issue · 3 comments

There are two class use KotshiJsonAdapterFactory, error occurred when I compile the project.

For the following class:

import com.squareup.moshi.JsonAdapter
import se.ansman.kotshi.KotshiJsonAdapterFactory

@KotshiJsonAdapterFactory
abstract class CoreJsonAdapterFactory : JsonAdapter.Factory {
companion object {
val INSTANCE: CoreJsonAdapterFactory = KotshiCoreJsonAdapterFactory()
}
}

import com.squareup.moshi.JsonAdapter
import se.ansman.kotshi.KotshiJsonAdapterFactory

@KotshiJsonAdapterFactory
abstract class CommonJsonAdapterFactory : JsonAdapter.Factory {
companion object {
val INSTANCE: CommonJsonAdapterFactory = KotshiCommonJsonAdapterFactory()
}
}

Can't the KotshiJsonAdapterFactory annotation be used twice?

No, not within the same compilation (Gradle) module. It makes no sense really as the factories would be identical. What is your use case?

It is only used to build Moshi.

The code:
internal val moshi = Moshi.Builder()
...
// .add(CommonJsonAdapterFactory.INSTANCE)
.add(CoreJsonAdapterFactory.INSTANCE)
.add(ReactionsAdapter())
.build()

When I use one of them, it compile successfully

I have solved the issue, two classes can't be in the same module.

Thanks