package com.cvte.dss.ups.camera.utils;

import android.util.Log;
import com.google.gson.Gson;
import g.h0.c.l;
import java.lang.reflect.Type;

/* JADX INFO: compiled from: JsonUtils.kt */
/* JADX INFO: loaded from: classes.dex */
public final class JsonUtils {
    private static final String TAG = "JsonUtils";
    public static final JsonUtils INSTANCE = new JsonUtils();
    private static final Gson gson = new Gson();

    private JsonUtils() {
    }

    public final <T> T fromJson(String str, Class<T> cls) {
        l.g(str, "json");
        l.g(cls, "classOfT");
        try {
            return (T) gson.fromJson(str, (Class) cls);
        } catch (Exception e2) {
            Log.e(TAG, "parser json failed", e2);
            return null;
        }
    }

    public final String toJson(Object obj) {
        l.g(obj, "json");
        String json = gson.toJson(obj);
        l.b(json, "gson.toJson(json)");
        return json;
    }

    public final <T> T fromJson(String str, Type type) {
        l.g(str, "json");
        l.g(type, "typeOfT");
        try {
            return (T) gson.fromJson(str, type);
        } catch (Exception e2) {
            Log.e(TAG, "parser json failed", e2);
            return null;
        }
    }
}
