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

import X.JMB;
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.s;
import com.google.gson.u;
import com.google.gson.v;

public final class ModelCheckerTypeAdapterFactory implements v {
    static {
        Covode.recordClassIndex(94637);
    }

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

            /* JADX WARNING: type inference failed for: r0v5, types: [java.lang.Throwable, com.google.gson.s] */
            public T read(com.google.gson.c.a aVar) {
                if (aVar.LJFF() == b.NULL) {
                    aVar.LJIIJ();
                    return null;
                }
                T t = (JMB) LIZ.read(aVar);
                try {
                    t.checkValid();
                    return t;
                } catch (n e) {
                    throw e;
                } catch (Throwable th) {
                    throw new s(th);
                }
            }

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