Closed alihabbash closed 6 years ago
Have you tegisterd the type adapters with the gsonisntance that you provide to retrofit?
On Sun, Aug 5, 2018, 4:06 PM Ali Habbash notifications@github.com wrote:
Hi, I have an AutoValue class for newsResponse and RxJava with Retrofit and my AutoValue type adapter is
@AutoValue public abstract class NewsResponse implements Parcelable {
public static TypeAdapter
typeAdapter(Gson gson){ return new AutoValue_NewsResponse.GsonTypeAdapter(gson); } @SerializedName("api_text") public abstract String isSuccess();
@SerializedName("news") public abstract List
getNews(); }
my NewsDetails class is
@AutoValue public abstract class NewsDetails implements Parcelable{
public static TypeAdapter
typeAdapter(Gson gson){ return new AutoValue_NewsDetails.GsonTypeAdapter(gson); } @SerializedName("id") public abstract String getNewsId();
@SerializedName("description") public abstract String getDescription();
@SerializedName("title") public abstract String getTitle();
@SerializedName("category") public abstract String getCategory();
@SerializedName("thumbnail") public abstract String getImageUrl();
@SerializedName("posted_time") public abstract String getPostedTime();
}
My Rxjava call is
model.getNews("1", "1", OrderBy.DESC) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> ToastUtils.showShort(throwable.getMessage())) .doOnSuccess(newsResponse -> view.setUpRecyclerView(newsResponse.getNews())) .subscribeOn(Schedulers.io()) .subscribe();
My problem is I got this error when I make a Retrofit call
Failed to invoke public com.ramiissa.dubaiing.data.network.model.news.NewsResponse() with no args
The Api Response from server looks like this
{ "api_status": "200", "api_text": "success", "api_version": "1.5.2", "news": [ { "id": "1", "title": "news1news1 news1 news1 news1 news1 news1 news1 news1", "description": "news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1 news1", "category": "2", "category_name": "English", "thumbnail": "http://www.dubai-ing.net/upload/photos/2018/08/nAlMzZ4xZ3XfdMsyT5bj_05_c908f62a43c4f7c8d04e38b29858d9e1_image.jpg", "posted_time": "5 hours ago", "tags_array": [ "news1" ] } ] }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rharter/auto-value-gson/issues/184, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPJbm1_G5V7L2yqboeM9OEcN7jzaztJks5uN143gaJpZM4VviQr .
Thanks It's worked. I forgot to register the type adapter to Retrofit.
Hi, I have an AutoValue class for newsResponse and
RxJava
withRetrofit
and my AutoValue type adapter is}
my
NewsDetails
class isMy Rxjava call is
My problem is I got this error when I make a Retrofit call
The Api Response from server looks like this