package com.facebook.internal; import android.os.Bundle; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes.dex */ public class BundleJSONConverter { private static final Map, Setter> a = new HashMap(); public interface Setter { void a(Bundle bundle, String str, Object obj) throws JSONException; } static { a.put(Boolean.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.1 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { bundle.putBoolean(str, ((Boolean) obj).booleanValue()); } }); a.put(Integer.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.2 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { bundle.putInt(str, ((Integer) obj).intValue()); } }); a.put(Long.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.3 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { bundle.putLong(str, ((Long) obj).longValue()); } }); a.put(Double.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.4 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { bundle.putDouble(str, ((Double) obj).doubleValue()); } }); a.put(String.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.5 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { bundle.putString(str, (String) obj); } }); a.put(String[].class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.6 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { throw new IllegalArgumentException("Unexpected type from JSON"); } }); a.put(JSONArray.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.7 @Override // com.facebook.internal.BundleJSONConverter.Setter public void a(Bundle bundle, String str, Object obj) throws JSONException { JSONArray jSONArray = (JSONArray) obj; ArrayList arrayList = new ArrayList<>(); if (jSONArray.length() == 0) { bundle.putStringArrayList(str, arrayList); return; } for (int i = 0; i < jSONArray.length(); i++) { Object obj2 = jSONArray.get(i); if (!(obj2 instanceof String)) { throw new IllegalArgumentException("Unexpected type in an array: " + obj2.getClass()); } arrayList.add((String) obj2); } bundle.putStringArrayList(str, arrayList); } }); } public static Bundle a(JSONObject jSONObject) throws JSONException { Bundle bundle = new Bundle(); Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); Object obj = jSONObject.get(next); if (obj != null && obj != JSONObject.NULL) { if (obj instanceof JSONObject) { bundle.putBundle(next, a((JSONObject) obj)); } else { Setter setter = a.get(obj.getClass()); if (setter == null) { throw new IllegalArgumentException("Unsupported type: " + obj.getClass()); } setter.a(bundle, next, obj); } } } return bundle; } }