package com.amplifyframework.core.model.types;

import com.google.gson.d;
import com.google.gson.e;
import com.google.gson.g;
import com.google.gson.h;
import com.google.gson.i;
import com.google.gson.m;
import com.google.gson.u;
import com.google.gson.v;
import java.io.IOException;
import java.lang.reflect.Type;
import xk.a;
import xk.b;
import xk.c;

/* loaded from: classes4.dex */
public final class GsonJavaTypeAdapters {

    /* loaded from: classes4.dex */
    public static final class ClassTypeAdapterFactory implements v {

        /* loaded from: classes4.dex */
        static final class ClassTypeAdapter extends u {
            ClassTypeAdapter() {
            }

            private static Class<?> boxForPrimitiveLabel(String str) {
                str.hashCode();
                char c10 = 65535;
                switch (str.hashCode()) {
                    case -1325958191:
                        if (str.equals("double")) {
                            c10 = 0;
                            break;
                        }
                        break;
                    case 104431:
                        if (str.equals("int")) {
                            c10 = 1;
                            break;
                        }
                        break;
                    case 3039496:
                        if (str.equals("byte")) {
                            c10 = 2;
                            break;
                        }
                        break;
                    case 3052374:
                        if (str.equals("char")) {
                            c10 = 3;
                            break;
                        }
                        break;
                    case 3327612:
                        if (str.equals("long")) {
                            c10 = 4;
                            break;
                        }
                        break;
                    case 3625364:
                        if (str.equals("void")) {
                            c10 = 5;
                            break;
                        }
                        break;
                    case 64711720:
                        if (str.equals("boolean")) {
                            c10 = 6;
                            break;
                        }
                        break;
                    case 97526364:
                        if (str.equals("float")) {
                            c10 = 7;
                            break;
                        }
                        break;
                    case 109413500:
                        if (str.equals("short")) {
                            c10 = '\b';
                            break;
                        }
                        break;
                }
                switch (c10) {
                    case 0:
                        return Double.class;
                    case 1:
                        return Integer.class;
                    case 2:
                        return Byte.class;
                    case 3:
                        return Character.class;
                    case 4:
                        return Long.class;
                    case 5:
                        return Void.class;
                    case 6:
                        return Boolean.class;
                    case 7:
                        return Float.class;
                    case '\b':
                        return Short.class;
                    default:
                        throw new IllegalArgumentException("No primitive with name = " + str);
                }
            }

            @Override // com.google.gson.u
            public Class<?> read(a aVar) throws IOException {
                if (aVar.L() == b.NULL) {
                    aVar.G();
                    return null;
                }
                String J = aVar.J();
                try {
                    try {
                        return Class.forName(J);
                    } catch (ClassNotFoundException unused) {
                        return boxForPrimitiveLabel(J);
                    }
                } catch (IllegalArgumentException unused2) {
                    throw new IOException("Unable to deserialize class for " + J);
                }
            }

            @Override // com.google.gson.u
            public void write(c cVar, Class<?> cls) throws IOException {
                if (cls == null) {
                    cVar.t();
                } else {
                    cVar.Q(cls.getName());
                }
            }
        }

        @Override // com.google.gson.v
        public <T> u create(d dVar, com.google.gson.reflect.a aVar) {
            if (Class.class.isAssignableFrom(aVar.getRawType())) {
                return new ClassTypeAdapter();
            }
            return null;
        }
    }

    /* loaded from: classes4.dex */
    public static final class StringDeserializer implements h {
        @Override // com.google.gson.h
        public String deserialize(i iVar, Type type, g gVar) throws m {
            if (iVar.q()) {
                return iVar.i().l();
            }
            if (iVar.o()) {
                return iVar.toString();
            }
            throw new m("Failed to parse String from " + iVar);
        }
    }

    private GsonJavaTypeAdapters() {
    }

    public static void register(e eVar) {
        eVar.c(String.class, new StringDeserializer()).d(new ClassTypeAdapterFactory());
    }
}
