Scarlet icon indicating copy to clipboard operation
Scarlet copied to clipboard

Type not supported, please update documentation and demo app

Open JoaquimLey opened this issue 6 years ago • 3 comments

Hey 👋, first of all, I would like to thank you for the work you've put into building this, and sharing with the community.


I'm getting some trouble getting scarlet to work properly for some reason any model that I have in my service always throw:

Type is not supported by this MessageAdapterFactory

e.g.

Caused by: java.lang.IllegalArgumentException: Type is not supported by this MessageAdapterFactory: class com.ethmanage.websocket.coinbase.model.RemoteTicker

When I build the demo app form this source it works.

I've literally copy-pasted your gdax implementation to my project and I still get the same error(s) but now with your model.

Service


interface WebSocketCoinbaseApi {

    @Receive
    fun observeWebSocketEvent(): Flowable<WebSocketEvent>

    @Send
    fun sendSubscribe(subscribe: WebSocketSubscribe)

    @Receive
    fun observeTicker(): Flowable<RemoteTicker>
}

Model

data class RemoteTicker(
    val type: String,
    val product_id: RemoteProductId,
    val sequence: Long,
    val time: String,
    val price: String,
    val side: String,
    val last_size: String,
    val best_bid: String,
    val best_ask: String
)

Both WebSocketSubscribe and RemoteTicker throw

My setup is basically the same as yours with the adapters:

class CoinbaseScarletAdapter {

    @FromJson
    fun productIdFromJson(string: String): RemoteProductId {
        return RemoteProductId.valueOf(string)
    }

    @ToJson
    fun productIdToJson(data: RemoteProductId): String {
        return data.text
    }

    @FromJson
    fun subscribeTypeFromJson(string: String): WebSocketSubscribe.Type {
        return WebSocketSubscribe.Type.valueOf(string)
    }

    @ToJson
    fun subscribeTypeToJson(data: WebSocketSubscribe.Type): String {
        return data.text
    }

    @FromJson
    fun subscribeChannelFromJson(string: String): WebSocketSubscribe.Channel {
        return WebSocketSubscribe.Channel.valueOf(string)
    }

    @ToJson
    fun subscribeChannelToJson(data: WebSocketSubscribe.Channel): String {
        return data.text
    }
}

Even if change the productId to a String I still get the same crash, here are my dependencies:

dependencies {
    (...)

    // Scarlet
    def scarlet_version = '0.2.1-alpha4'

    implementation "com.github.tinder.scarlet:scarlet:$scarlet_version"
    implementation "com.github.tinder.scarlet:scarlet-protocol-websocket-okhttp:$scarlet_version"
    implementation("com.github.tinder.scarlet:scarlet-lifecycle-android:$scarlet_version") {
        exclude group: 'com.github.tinder', module: 'scarlet'
    }
    implementation "com.github.tinder.scarlet:scarlet-message-adapter-moshi:0.2.1-alpha3"
    implementation "com.github.tinder.scarlet:scarlet-stream-adapter-rxjava2:$scarlet_version"
}

I've tried with stable v1.9.0 still get the same error(s). I've also tried to only connect and get the same crash as it happens at instantiation.

The instantiation module I have exactly the same as the 0.2.x branch (using Koin too).


I would appreciate if you could take the time to:

  1. Point me to where I'm overlooking something very stupid;

  2. I would like to know if possible if you guys could either publish the 2.5.0-SNAPSHOP if there's something that different from the version I'm using ☝️ (I can't import from maven);

  3. Make your demo module app in this repository to import directly from maven instead of the source as this will give both a more reproducible state;

I've pasted the complete (from koin) stacktrace here: https://pastebin.com/b6eBriiB

I've also tried to manually instantiate Scarlet and get the same Type exception.

Thank you for your time and attention 🙏and please let me know if you need any more details.


Related: #95

JoaquimLey avatar Aug 14 '19 10:08 JoaquimLey

Ok for some miracle I was able to find the reason why:

I had to use this:

import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory

Instead of this

import com.squareup.moshi.KotlinJsonAdapterFactory

So you must add the kotlin-moshi dependency if you use Kotlin:

implementation "com.squareup.moshi:moshi-kotlin:$versions.moshi"

Since I am building the WebSocket part on an isolated module, I did not have any other dependencies besides koin and scarlet, and wrongly assumed this artifact would pull moshi scarlet-message-adapter-moshi.

Leaving this open for some feedback from the team, as there might be another reason/solution.

Note: My adapter uses valueOf(string) because I don't have a text property and directly map the Enum class's name.

JoaquimLey avatar Aug 14 '19 12:08 JoaquimLey

can you try using moshi code gen artifact to decorate RemoteTicker? then you won't need the kotlin-moshi artifact, see: https://github.com/square/moshi#codegen

aaronweihe avatar Aug 16 '19 17:08 aaronweihe

To be honest, I didn't try it, but maybe you are right! Still, would you think that having this information on the README to be valuable?

Thanks for your time

JoaquimLey avatar Aug 19 '19 13:08 JoaquimLey