Skip to content

How to use MoshiConverterFactory for generic type of model classes in android ? #1714

Closed

Description

@GopalLR

Hi, Can I use MoshiConverterFactory and GsonConverterFactory in single retrofit instance ?

I'm working in one project which has morethen 50 APIs and all APIs response structure is same like below :

{

"status": 200,

"message": "Login successfully.",

"result": {

}

}

I create base model class with generic type

@JsonClass(generateAdapter = true)

data class BaseModel(

@Json(name = "status")

val status: Int,

@Json(name = "message")

val message: String,

@Json(name = "result")

val result: Map<String, T>

)

@JsonClass(generateAdapter = true)

data class AccessToken(

@Json(name = "accessToken")

val accessToken: String

)

It's give error like :

Unable to create converter for com.app.sample.data.model.BaseModel<com.app.sample.data.model.AccessToken> for method AuthService.loginUser in android

How to fixed this issue using MoshiConverterFactory ?

I look forward to hearing from you.

Activity

  1. ZacSweers commented on Aug 2, 2023

    @ZacSweers
    Collaborator

    This is not the Retrofit issue tracker. Please ask questions in its discussions section here: https://github.com/square/retrofit/discussions

  2. JakeWharton commented on Aug 15, 2023

    @JakeWharton
    Collaborator

    This is not a problem with Retrofit. Moshi is failing to create an adapter for the supplied type.

    However, you haven't provided the full stacktrace of the failure so it's impossible to know what's going on. Going to move to a discussion here.

  3. locked and limited conversation to collaborators on Aug 15, 2023
  4. converted this issue into a discussion #1721 on Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions