package g.e.b.g0.f0;

import g.e.b.d0;
import g.e.b.e0;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class a<E> extends d0<Object> {
    public static final e0 a = new C0061a();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Class<E> f4041b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final d0<E> f4042c;

    /* JADX INFO: renamed from: g.e.b.g0.f0.a$a, reason: collision with other inner class name */
    public class C0061a implements e0 {
        @Override // g.e.b.e0
        public <T> d0<T> b(g.e.b.j jVar, g.e.b.h0.a<T> aVar) {
            Type type = aVar.f4166b;
            boolean z2 = type instanceof GenericArrayType;
            if (!z2 && (!(type instanceof Class) || !((Class) type).isArray())) {
                return null;
            }
            Type genericComponentType = z2 ? ((GenericArrayType) type).getGenericComponentType() : ((Class) type).getComponentType();
            return new a(jVar, jVar.d(new g.e.b.h0.a<>(genericComponentType)), g.e.b.g0.a.f(genericComponentType));
        }
    }

    public a(g.e.b.j jVar, d0<E> d0Var, Class<E> cls) {
        this.f4042c = new p(jVar, d0Var, cls);
        this.f4041b = cls;
    }

    @Override // g.e.b.d0
    public Object a(g.e.b.i0.a aVar) throws IOException {
        if (aVar.I() == g.e.b.i0.b.NULL) {
            aVar.E();
            return null;
        }
        ArrayList arrayList = new ArrayList();
        aVar.a();
        while (aVar.q()) {
            arrayList.add(this.f4042c.a(aVar));
        }
        aVar.g();
        int size = arrayList.size();
        Object objNewInstance = Array.newInstance((Class<?>) this.f4041b, size);
        for (int i2 = 0; i2 < size; i2++) {
            Array.set(objNewInstance, i2, arrayList.get(i2));
        }
        return objNewInstance;
    }

    @Override // g.e.b.d0
    public void b(g.e.b.i0.c cVar, Object obj) {
        if (obj == null) {
            cVar.m();
            return;
        }
        cVar.c();
        int length = Array.getLength(obj);
        for (int i2 = 0; i2 < length; i2++) {
            this.f4042c.b(cVar, (E) Array.get(obj, i2));
        }
        cVar.g();
    }
}
