How can I use moshi-jsonapi in Retrofit2?
See original GitHub issueTokenModel.java
@JsonApi(type = "tokens")
public class TokenModel extends Resource {
@Json(name = "cell_phone")
public String cellPhone;
}
TestService.java:
public interface TestService {
@POST("token")
Call<TokenModel> newOtp(@Body TokenModel tokenModel);
}
TestProvider.java:
public class TestProvider {
private TestService testService;
public TestProvider() {
OkHttpClient httpClient = new OkHttpClient();
Retrofit refRetrofit = new Retrofit.Builder()
.baseUrl(ClientConfigs.BASE_URL)
.client(httpClient)
.addConverterFactory(MoshiConverterFactory.create())
// .addConverterFactory(????????????????????????????)
.build();
testService = refRetrofit.create(TestService.class);
}
publicTestService getTestService() {
return testService;
}
}
If I use MoshiConverterFactory make error Unable to create converter for class com.xxxx.xxxx.model.TokenModel!
Use Retrofit:
TsetProvider testProvider = new TestProvider();
TestService testService = testProvider.getTestService();
TokenModel tokenModel = new TokenModel();
tokenModel.cellPhone = "123123123";
Call<TokenModel> call = testService.newOtp(tokenModel);
call.enqueue(new Callback<TokenModel>() {
@Override
public void onResponse(Call<TokenModel> call, Response<TokenModel> response) {
}
@Override
public void onFailure(Call<TokenModel> call, Throwable t) {
}
});
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How can I use jsonapi in Retrofit2? - Stack Overflow
From moshi-jsonapi documentation you need to add the libraries factory to the moshi instance: // First create the factory JsonAdapter.
Read more >Moshi with Retrofit in Kotlin - ProAndroidDev
Hello everyone! Today I want to show how to implement Moshi with Retrofit (new project or replacing Gson) in an Android project.
Read more >How to parse JSON with Retrofit Converters using Kotlin
In this tutorial, I will show you how to parse JSON using the Retrofit converters: Gson, Moshi, Kotlinx Serialization and Jackson!
Read more >How to Send JSON Data in a POST Request in Android
I have put together a tutorial with code samples in Java covering how to send JSON data in a HTTP POST request within...
Read more >Everything You Need To Know About Retrofit and Moshi in ...
In this video, you will learn about Retrofit in Android To become a great Android Developer check out our Android Learning Path: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a boilerplate code for a moshi converter factory:
I’d add that to documentation ASAIC.
@lkakireddy Here is the gist for retrofit integration but it seems to be broken for now 🤕