package com.ss.android.ugc.aweme.net;

import X.C0367P8y;
import X.JMC;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.google.gson.b.a;
import com.google.gson.c.b;
import com.google.gson.c.c;
import com.google.gson.n;
import com.google.gson.u;
import com.google.gson.v;
import com.ss.android.ugc.aweme.base.api.BaseResponse;

public class BaseResponseObjectTypeAdapterFactory implements v {
    static {
        Covode.recordClassIndex(94629);
    }

    public <T> u<T> create(Gson gson, a<T> aVar) {
        if (!BaseResponse.class.isAssignableFrom(aVar.rawType)) {
            return null;
        }
        final u<T> LIZ = gson.LIZ((v) this, aVar);
        return new u<T>() {
            static {
                Covode.recordClassIndex(94630);
            }

            public T read(com.google.gson.c.a aVar) {
                if (aVar.LJFF() == b.NULL) {
                    aVar.LJIIJ();
                    return null;
                }
                try {
                    T t = (BaseResponse) LIZ.read(aVar);
                    if (t.extra != null && t.extra.now > 0) {
                        C0367P8y.LIZ = t.extra.now;
                    }
                    return t;
                } catch (n e) {
                    if (e.getCause() instanceof JMC) {
                        throw e.getCause();
                    }
                    throw e;
                }
            }

            public void write(c cVar, T t) {
                if (t == null) {
                    cVar.LJFF();
                } else {
                    LIZ.write(cVar, t);
                }
            }
        };
    }
}
