com.facebook.react.bridge.ReadableMapKeySetIterator Java Examples

The following examples show how to use com.facebook.react.bridge.ReadableMapKeySetIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RCTConvert.java    From react-native-twilio-chat with MIT License 6 votes vote down vote up
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }
    HashMap map = new HashMap<String, Object>();
    ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator();
    while (keySetIterator.hasNextKey()) {
        String key = keySetIterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch(type) {
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key));
                map.put(key, attributes);
                break;
            default:
                // do nothing
        }
    }
    return map;
}
 
Example #2
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMapIterateOverNestedMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedMap();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator firstLevelIterator = map.keySetIterator();
  String firstLevelKey = firstLevelIterator.nextKey();
  assertEquals(firstLevelKey, "weHaveToGoDeeper");

  ReadableNativeMap secondMap = map.getMap("weHaveToGoDeeper");
  ReadableMapKeySetIterator secondLevelIterator = secondMap.keySetIterator();
  String secondLevelKey = secondLevelIterator.nextKey();
  assertEquals(secondLevelKey, "inception");
  assertTrue(secondMap.getBoolean(secondLevelKey));
}
 
Example #3
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMapIterateOverMapWithBasicTypes() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  Set<String> keys = new HashSet<String>();
  while (mapIterator.hasNextKey()) {
    keys.add(mapIterator.nextKey());
  }

  Set<String> expectedKeys = new HashSet<String>(
      Arrays.asList("stringKey", "doubleKey", "intKey", "booleanKey", "nullKey"));
  assertEquals(keys, expectedKeys);
}
 
Example #4
Source File: OAuthManagerProviders.java    From react-native-oauth with MIT License 6 votes vote down vote up
static private OAuthRequest addParametersToRequest(
  OAuthRequest request,
  final String access_token,
  @Nullable final ReadableMap params
) {
  if (params != null && params.hasKey("params")) {
    ReadableMapKeySetIterator iterator = params.keySetIterator();
    while (iterator.hasNextKey()) {
      String key = iterator.nextKey();
      ReadableType readableType = params.getType(key);
      switch(readableType) {
        case String:
          String val = params.getString(key);
          // String escapedVal = Uri.encode(val);
          if (val.equals("access_token")) {
            val = access_token;
          }
          request.addParameter(key, val);
          break;
        default:
          throw new IllegalArgumentException("Could not read object with key: " + key);
      }
    }
  }
  return request;
}
 
Example #5
Source File: NativeViewHierarchyOptimizer.java    From react-native-GPay with MIT License 6 votes vote down vote up
private static boolean isLayoutOnlyAndCollapsable(@Nullable ReactStylesDiffMap props) {
  if (props == null) {
    return true;
  }

  if (props.hasKey(ViewProps.COLLAPSABLE) && !props.getBoolean(ViewProps.COLLAPSABLE, true)) {
    return false;
  }

  ReadableMapKeySetIterator keyIterator = props.mBackingMap.keySetIterator();
  while (keyIterator.hasNextKey()) {
    if (!ViewProps.isLayoutOnly(props.mBackingMap, keyIterator.nextKey())) {
      return false;
    }
  }
  return true;
}
 
Example #6
Source File: Utils.java    From photo-viewer with Apache License 2.0 6 votes vote down vote up
/**
 * Converts Facebook's ReadableMap to a Java Map<>
 *
 * @param readableMap The Readable Map to parse
 * @return a Java Map<> to be used in memory
 */
public static Map<String, Object> toMap(@Nullable ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    if (!iterator.hasNextKey()) {
        return null;
    }

    Map<String, Object> result = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        result.put(key, toObject(readableMap, key));
    }

    return result;
}
 
Example #7
Source File: FlurryModule.java    From react-native-flurry-sdk with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> toMap(final ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    if (!iterator.hasNextKey()) {
        return null;
    }

    Map<String, String> result = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        result.put(key, readableMap.getString(key));
    }

    return result;
}
 
Example #8
Source File: FlurryModule.java    From react-native-flurry-sdk with Apache License 2.0 6 votes vote down vote up
@ReactMethod
public void getConfigStringMap(ReadableMap keyAndDefault, Promise promise) {
    try {
        WritableMap map = Arguments.createMap();
        if (keyAndDefault != null) {
            ReadableMapKeySetIterator iterator = keyAndDefault.keySetIterator();
            while (iterator.hasNextKey()) {
                String key = iterator.nextKey();
                String defaultValue = keyAndDefault.getString(key);
                map.putString(key, FlurryConfig.getInstance().getString(key, defaultValue));
            }
        }
        promise.resolve(map);
    } catch (IllegalViewOperationException e) {
        promise.reject("Flurry.getConfigString", e);
    }
}
 
Example #9
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 群踢人
 *
 * @param params
 */
@ReactMethod
public void kickGroupMember(ReadableMap params, Callback callback) {
    final String groupId = params.getString("groupId");
    ReadableMap map = params.getMap("members");
    ReadableMapKeySetIterator keySet = map.keySetIterator();
    Map<String, String> memberMap = new HashMap<>();
    while (keySet.hasNextKey()) {
        ReadableMap item = map.getMap(keySet.nextKey());
        String userId = item.getString("xmppId");
        String name = item.getString("name");
        memberMap.put(name, userId);
    }
    if (TextUtils.isEmpty(groupId) || memberMap.size() == 0) {
        return;
    }
    ConnectionUtil.getInstance().delGroupMember(groupId, memberMap);
    sendEvent("closeKickMembers", new WritableNativeMap());
    toast("成员已移除");
}
 
Example #10
Source File: ReactNativeSmooch.java    From react-native-smooch with MIT License 6 votes vote down vote up
private Map<String, Object> getUserProperties(ReadableMap properties) {
    ReadableMapKeySetIterator iterator = properties.keySetIterator();
    Map<String, Object> userProperties = new HashMap<>();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = properties.getType(key);
        if (type == ReadableType.Boolean) {
            userProperties.put(key, properties.getBoolean(key));
        } else if (type == ReadableType.Number) {
            userProperties.put(key, properties.getDouble(key));
        } else if (type == ReadableType.String) {
            userProperties.put(key, properties.getString(key));
        }
    }

    return userProperties;
}
 
Example #11
Source File: FlurryAnalyticsModule.java    From react-native-flurry-analytics with MIT License 6 votes vote down vote up
private static Map<String, String> toMap(@Nullable ReadableMap readableMap) {
  if (readableMap == null) {
    return null;
  }

  ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
  if (!iterator.hasNextKey()) {
    return null;
  }

  Map<String, String> result = new HashMap<>();
  while (iterator.hasNextKey()) {
    String key = iterator.nextKey();
    result.put(key, readableMap.getString(key));
  }

  return result;
}
 
Example #12
Source File: RCTConvert.java    From react-native-twilio-ip-messaging with MIT License 6 votes vote down vote up
public static HashMap<String, Object> readableMapToHashMap(ReadableMap readableMap) {
    if (readableMap == null) {
        return null;
    }
    HashMap map = new HashMap<String, Object>();
    ReadableMapKeySetIterator keySetIterator = readableMap.keySetIterator();
    while (keySetIterator.hasNextKey()) {
        String key = keySetIterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch(type) {
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                HashMap<String, Object> attributes = new RCTConvert().readableMapToHashMap(readableMap.getMap(key));
                map.put(key, attributes);
                break;
            default:
                // do nothing
        }
    }
    return map;
}
 
Example #13
Source File: IntercomModule.java    From react-native-intercom with MIT License 5 votes vote down vote up
private Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) {
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    Map<String, Object> deconstructedMap = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch (type) {
            case Null:
                deconstructedMap.put(key, null);
                break;
            case Boolean:
                deconstructedMap.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                deconstructedMap.put(key, readableMap.getDouble(key));
                break;
            case String:
                deconstructedMap.put(key, readableMap.getString(key));
                break;
            case Map:
                deconstructedMap.put(key, recursivelyDeconstructReadableMap(readableMap.getMap(key)));
                break;
            case Array:
                deconstructedMap.put(key, recursivelyDeconstructReadableArray(readableMap.getArray(key)));
                break;
            default:
                throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
        }

    }
    return deconstructedMap;
}
 
Example #14
Source File: ReactNativeJson.java    From react-native-couchbase-lite with MIT License 5 votes vote down vote up
public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
    JSONObject object = new JSONObject();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        switch (readableMap.getType(key)) {
            case Null:
                object.put(key, JSONObject.NULL);
                break;
            case Boolean:
                object.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                object.put(key, readableMap.getDouble(key));
                break;
            case String:
                object.put(key, readableMap.getString(key));
                break;
            case Map:
                object.put(key, convertMapToJson(readableMap.getMap(key)));
                break;
            case Array:
                object.put(key, convertArrayToJson(readableMap.getArray(key)));
                break;
        }
    }
    return object;
}
 
Example #15
Source File: SegmentAnalyticsModule.java    From react-native-segment-analytics with MIT License 5 votes vote down vote up
/**
 * Transforms ReadableMap to java.util.Map object
 * @param readableMap should not be null or empty
 * @return Map object of readableMap
 */
private Map<String, Object> toMap (ReadableMap readableMap) {
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    Map<String, Object> map = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType readableType = readableMap.getType(key);

        switch (readableType) {
            case Null:
                map.put(key, null);
                break;
            case Boolean:
                map.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                // Can be int or double.
                map.put(key, readableMap.getDouble(key));
                break;
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                map.put(key, this.toMap(readableMap.getMap(key)));
                break;
            case Array:
                map.put(key, this.toArray(readableMap.getArray(key)));
                break;
            default:
                throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
        }
    }
    return map;
}
 
Example #16
Source File: OptionsHelper.java    From react-native-lock with MIT License 5 votes vote down vote up
public static  Map<String, Object> convertReadableMapToMap(ReadableMap reactMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator keySet = reactMap.keySetIterator();
    while (keySet.hasNextKey()) {
        String key = keySet.nextKey();
        Object object = null;
        switch (reactMap.getType(key)) {
            case Array:
                object = convertReadableArrayToArray(reactMap.getArray(key));
                break;
            case Boolean:
                object = reactMap.getBoolean(key);
                break;
            case Map:
                object = convertReadableMapToMap(reactMap.getMap(key));
                break;
            case Null:
                object = null;
                break;
            case Number:
                try {
                    object = reactMap.getDouble(key);
                } catch (java.lang.ClassCastException e) {
                    object = reactMap.getInt(key);
                }
                break;
            case String:
                object = reactMap.getString(key);
                break;
            default:
                Log.e(TAG, "Unknown type: " + reactMap.getType(key) + " for key: " + key);
        }
        map.put(key, object);
    }
    return map;
}
 
Example #17
Source File: Utils.java    From react-native-update with MIT License 5 votes vote down vote up
public static JSONObject convertReadableToJsonObject(ReadableMap map) {
    JSONObject jsonObj = new JSONObject();
    ReadableMapKeySetIterator it = map.keySetIterator();
    while (it.hasNextKey()) {
        String key = it.nextKey();
        ReadableType type = map.getType(key);
        try {
            switch (type) {
                case Map:
                    jsonObj.put(key, convertReadableToJsonObject(map.getMap(key)));
                    break;
                case Array:
                    jsonObj.put(key, convertReadableToJsonArray(map.getArray(key)));
                    break;
                case String:
                    jsonObj.put(key, map.getString(key));
                    break;
                case Number:
                    jsonObj.put(key, map.getDouble(key));
                    break;
                case Boolean:
                    jsonObj.put(key, map.getBoolean(key));
                    break;
                case Null:
                    jsonObj.put(key, null);
                    break;
                default:
                    throw new RuntimeException("Unrecognized type: " + type + " of key: " + key);
            }
        } catch (JSONException jsonException) {
            throw new RuntimeException("Error setting key: " + key + " in JSONObject", jsonException);
        }
    }

    return jsonObj;
}
 
Example #18
Source File: RealtimeMessagingAndroid.java    From RCTRealtimeMessagingAndroid with MIT License 5 votes vote down vote up
private Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) {
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    Map<String, Object> deconstructedMap = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch (type) {
            case Null:
                deconstructedMap.put(key, null);
                break;
            case Boolean:
                deconstructedMap.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                deconstructedMap.put(key, readableMap.getDouble(key));
                break;
            case String:
                deconstructedMap.put(key, readableMap.getString(key));
                break;
            case Map:
                deconstructedMap.put(key, recursivelyDeconstructReadableMap(readableMap.getMap(key)));
                break;
            case Array:
                deconstructedMap.put(key, recursivelyDeconstructReadableArray(readableMap.getArray(key)));
                break;
            default:
                throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
        }

    }
    return deconstructedMap;
}
 
Example #19
Source File: JsonConvert.java    From react-native-cordova with MIT License 5 votes vote down vote up
public static JSONObject reactToJSON(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    while(iterator.hasNextKey()){
        String key = iterator.nextKey();
        ReadableType valueType = readableMap.getType(key);
        switch (valueType){
            case Null:
                jsonObject.put(key,JSONObject.NULL);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                try {
                    jsonObject.put(key, readableMap.getInt(key));
                } catch(Exception e) {
                    jsonObject.put(key, readableMap.getDouble(key));
                }
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, reactToJSON(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, reactToJSON(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
Example #20
Source File: RNDataWedgeIntentsModule.java    From react-native-datawedge-intents with MIT License 5 votes vote down vote up
private Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) {
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
    Map<String, Object> deconstructedMap = new HashMap<>();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);
        switch (type) {
            case Null:
                deconstructedMap.put(key, null);
                break;
            case Boolean:
                deconstructedMap.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                deconstructedMap.put(key, readableMap.getDouble(key));
                break;
            case String:
                deconstructedMap.put(key, readableMap.getString(key));
                break;
            case Map:
                deconstructedMap.put(key, recursivelyDeconstructReadableMap(readableMap.getMap(key)));
                break;
            case Array:
                deconstructedMap.put(key, recursivelyDeconstructReadableArray(readableMap.getArray(key)));
                break;
            default:
                throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
        }
    }
    return deconstructedMap;
}
 
Example #21
Source File: MapUtil.java    From Instabug-React-Native with MIT License 5 votes vote down vote up
public static Map<String, Object> toMap(ReadableMap readableMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                map.put(key, null);
                break;
            case Boolean:
                map.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                map.put(key, readableMap.getDouble(key));
                break;
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                map.put(key, MapUtil.toMap(readableMap.getMap(key)));
                break;
            case Array:
                map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
                break;
        }
    }

    return map;
}
 
Example #22
Source File: MapUtil.java    From react-native-background-geolocation with Apache License 2.0 5 votes vote down vote up
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                jsonObject.put(key, null);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                jsonObject.put(key, readableMap.getDouble(key));
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
Example #23
Source File: JSONParser.java    From react-native-navigation with MIT License 5 votes vote down vote up
public JSONObject parse(ReadableMap map) {
    try {
        ReadableMapKeySetIterator it = map.keySetIterator();
        JSONObject result = new JSONObject();
        while (it.hasNextKey()) {
            String key = it.nextKey();
            switch (map.getType(key)) {
                case String:
                    result.put(key, map.getString(key));
                    break;
                case Number:
                    result.put(key, parseNumber(map, key));
                    break;
                case Boolean:
                    result.put(key, map.getBoolean(key));
                    break;
                case Array:
                    result.put(key, parse(map.getArray(key)));
                    break;
                case Map:
                    result.put(key, parse(map.getMap(key)));
                    break;
                default:
                    break;
            }
        }
        return result;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: RNDefaultPreferenceModule.java    From react-native-default-preference with MIT License 5 votes vote down vote up
@ReactMethod
public void setMultiple(ReadableMap data, Promise promise) {
  SharedPreferences.Editor editor = getEditor();
  ReadableMapKeySetIterator iter = data.keySetIterator();
  while(iter.hasNextKey()) {
    String key = iter.nextKey();
    editor.putString(key, data.getString(key)).commit();
  }
  promise.resolve(null);
}
 
Example #25
Source File: PjActions.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
private static Map<String, Object> formatMap(ReadableMap map) {
    Map<String, Object> value = new HashMap<>();
    ReadableMapKeySetIterator mapIt = map.keySetIterator();

    while (mapIt.hasNextKey()) {
        String mapKey = mapIt.nextKey();

        switch (map.getType(mapKey)) {
            case Null:
                value.put(mapKey, null);
                break;
            case String:
                value.put(mapKey, map.getString(mapKey));
                break;
            case Number:
                value.put(mapKey, map.getInt(mapKey));
                break;
            case Boolean:
                value.put(mapKey, map.getBoolean(mapKey));
                break;
            case Array:
                value.put(mapKey, map.getArray(mapKey).toArrayList());
                break;
            case Map:
                value.put(mapKey, formatMap(map.getMap(mapKey)));
                break;
            default:
                Log.w(TAG, "Unable to put extra information for intent: unknown type \""+ map.getType(mapKey) +"\"");
                break;
        }
    }

    return value;
}
 
Example #26
Source File: PjActions.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
private static void formatIntent(Intent intent, ReadableMap configuration) {
    if (configuration == null) {
        return;
    }

    ReadableMapKeySetIterator it = configuration.keySetIterator();
    while (it.hasNextKey()) {
        String key = it.nextKey();

        switch (configuration.getType(key)) {
            case Null:
                intent.putExtra(key, (String) null);
                break;
            case String:
                intent.putExtra(key, configuration.getString(key));
                break;
            case Number:
                intent.putExtra(key, configuration.getInt(key));
                break;
            case Boolean:
                intent.putExtra(key, configuration.getBoolean(key));
                break;
            case Map:
                intent.putExtra(key, (Serializable) formatMap(configuration.getMap(key)));
                break;
            default:
                Log.w(TAG, "Unable to put extra information for intent: unknown type \""+ configuration.getType(key) +"\"");
                break;
        }
    }
}
 
Example #27
Source File: SipMessageDTO.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
public static SipMessageDTO fromReadableMap(ReadableMap data) {
    SipMessageDTO result = new SipMessageDTO();

    if (data.hasKey("targetURI")) {
        result.setTargetUri(data.getString("targetURI"));
    }
    if (data.hasKey("headers")) {
        ReadableMap headersData = data.getMap("headers");
        ReadableMapKeySetIterator headersIt = headersData.keySetIterator();
        Map<String, String> headers = new HashMap<>();

        while (headersIt.hasNextKey()) {
            String key = headersIt.nextKey();
            headers.put(key, headersData.getString(key));
        }

        result.setHeaders(headers);
    }
    if (data.hasKey("contentType")) {
        result.setContentType(data.getString("contentType"));
    }
    if (data.hasKey("body")) {
        result.setBody(data.getString("body"));
    }

    return result;
}
 
Example #28
Source File: MapUtil.java    From vinci with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> toMap(ReadableMap readableMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                map.put(key, null);
                break;
            case Boolean:
                map.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                map.put(key, readableMap.getDouble(key));
                break;
            case String:
                map.put(key, readableMap.getString(key));
                break;
            case Map:
                map.put(key, MapUtil.toMap(readableMap.getMap(key)));
                break;
            case Array:
                map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
                break;
        }
    }

    return map;
}
 
Example #29
Source File: MapUtil.java    From vinci with Apache License 2.0 5 votes vote down vote up
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
    JSONObject jsonObject = new JSONObject();

    ReadableMapKeySetIterator iterator = readableMap.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();

        ReadableType type = readableMap.getType(key);

        switch (type) {
            case Null:
                jsonObject.put(key, null);
                break;
            case Boolean:
                jsonObject.put(key, readableMap.getBoolean(key));
                break;
            case Number:
                jsonObject.put(key, readableMap.getDouble(key));
                break;
            case String:
                jsonObject.put(key, readableMap.getString(key));
                break;
            case Map:
                jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
                break;
            case Array:
                jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
                break;
        }
    }

    return jsonObject;
}
 
Example #30
Source File: RNAGSGraphicsOverlay.java    From react-native-arcgis-mapview with MIT License 5 votes vote down vote up
private static Map<String, Object> readableMapToMap(ReadableMap rawMap) {
    Map<String, Object> map = new HashMap<>();
    ReadableMapKeySetIterator iterator = rawMap.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        map.put(key, rawMap.getString(key));
    }
    return map;
}