I need to pass my own JsonAdapter that implements the MoshiAdapterFactory interface to the NetworkingRouterConfig() then it throws an exception as soon as it get used.
UserJsonAdapter.kt:
class UserJsonAdapter: MoshiAdapterFactory {
private lateinit var borsh: Borsh
override fun create(borsh: Borsh): Object {
this.borsh = borsh
return Object()
}
@FromJson
fun fromJson(rawData: Any): Buffer<User> = Buffer.create(borsh = borsh, rawData = rawData, clazz = User::class.java)
}
Solana initialization:
Solana(
router = OkHttpNetworkingRouter(
endpoint = RPCEndpoint.mainnetBetaSolana,
httpClient = get(),
config = NetworkingRouterConfig(rules = listOf(UserRule()), moshiAdapters = listOf(UserJsonAdapter()))
)
)
Exception:
java.lang.IllegalArgumentException: Expected at least one @ToJson or @FromJson method on java.lang.Object at com.squareup.moshi.AdapterMethodsFactory.get(AdapterMethodsFactory.java:153) at com.squareup.moshi.Moshi$Builder.add(Moshi.java:223) at com.solana.networking.OkHttpNetworkingRouter$moshi$2.invoke(NetworkingRouter.kt:68) at com.solana.networking.OkHttpNetworkingRouter$moshi$2.invoke(NetworkingRouter.kt:60)