Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while passing own moshiAdapters to NetworkingRouterConfig #108

Open
tmcyrix opened this issue Oct 2, 2022 · 1 comment
Open

Comments

@tmcyrix
Copy link

tmcyrix commented Oct 2, 2022

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)

@tmcyrix tmcyrix changed the title Exception while passing a own moshiAdapters to NetworkingRouterConfig Exception while passing own moshiAdapters to NetworkingRouterConfig Oct 2, 2022
@ajamaica
Copy link
Contributor

This is now rewritten. I think it was not wheel documented. Check #107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants