package com.bytedance.creativex.model.mapping;

import X.6nr;
import X.M12;
import android.os.Bundle;
import android.os.Parcelable;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.google.gson.c.a;
import com.google.gson.c.c;
import com.google.gson.u;
import java.io.Serializable;
import java.util.Set;
import kotlin.h.b.n;

public final class SimpleBundleModelExtraAdapter extends u<Bundle> {
    public final Gson LIZ;
    public final 6nr LIZIZ;

    static {
        Covode.recordClassIndex(25307);
    }

    public final /* synthetic */ Object read(a aVar) {
        M12.LIZ((Object) aVar);
        Bundle bundle = new Bundle(getClass().getClassLoader());
        aVar.LIZJ();
        while (aVar.LJ()) {
            String LJII = aVar.LJII();
            6nr r1 = this.LIZIZ;
            n.LIZIZ(LJII, "");
            Object LIZ2 = this.LIZ.LIZ(aVar.LJIIIIZZ(), r1.LIZ(LJII));
            if (LIZ2 == null) {
                bundle.putSerializable(LJII, (Serializable) null);
            } else if (LIZ2 instanceof Parcelable) {
                bundle.putParcelable(LJII, (Parcelable) LIZ2);
            } else if (LIZ2 instanceof Serializable) {
                bundle.putSerializable(LJII, (Serializable) LIZ2);
            } else if (LIZ2 instanceof Byte) {
                bundle.putByte(LJII, ((Number) LIZ2).byteValue());
            } else if (LIZ2 instanceof Character) {
                bundle.putChar(LJII, ((Character) LIZ2).charValue());
            } else if (LIZ2 instanceof Boolean) {
                bundle.putBoolean(LJII, ((Boolean) LIZ2).booleanValue());
            } else if (LIZ2 instanceof Integer) {
                bundle.putInt(LJII, ((Number) LIZ2).intValue());
            } else if (LIZ2 instanceof Short) {
                bundle.putShort(LJII, ((Number) LIZ2).shortValue());
            } else if (LIZ2 instanceof Long) {
                bundle.putLong(LJII, ((Number) LIZ2).longValue());
            } else if (LIZ2 instanceof Float) {
                bundle.putFloat(LJII, ((Number) LIZ2).floatValue());
            } else if (LIZ2 instanceof Double) {
                bundle.putDouble(LJII, ((Number) LIZ2).doubleValue());
            } else if (LIZ2 instanceof String) {
                bundle.putString(LJII, (String) LIZ2);
            } else {
                throw new IllegalStateException("type not supported yet".toString());
            }
        }
        aVar.LIZLLL();
        return bundle;
    }

    public static Object LIZ(Bundle bundle, String str) {
        try {
            return bundle.get(str);
        } catch (Exception | OutOfMemoryError unused) {
            return null;
        }
    }

    public SimpleBundleModelExtraAdapter(Gson gson, 6nr r2) {
        M12.LIZ((Object) gson, (Object) r2);
        this.LIZ = gson;
        this.LIZIZ = r2;
    }

    public final /* synthetic */ void write(c cVar, Object obj) {
        Bundle bundle = (Bundle) obj;
        M12.LIZ((Object) cVar, (Object) bundle);
        cVar.LIZLLL();
        if (bundle.getClassLoader() == null) {
            bundle.setClassLoader(getClass().getClassLoader());
        }
        Set<String> keySet = bundle.keySet();
        n.LIZIZ(keySet, "");
        for (String str : keySet) {
            6nr r0 = this.LIZIZ;
            n.LIZIZ(str, "");
            Class LIZ2 = r0.LIZ(str);
            Object LIZ3 = LIZ(bundle, str);
            cVar.LIZ(str);
            cVar.LIZIZ(this.LIZ.LIZIZ(LIZ3, LIZ2));
        }
        cVar.LJ();
    }
}
