Files
react-native/ReactAndroid/src/main/java/com/facebook/react/util/ExceptionDataHelper.java
T
Andres Suarez 3b31e69e28 Tidy up license headers [2/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952694

fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
2019-10-16 10:06:34 -07:00

38 lines
1.1 KiB
Java

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.util;
import android.util.JsonWriter;
import com.facebook.react.bridge.JsonWriterHelper;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import javax.annotation.Nullable;
public class ExceptionDataHelper {
static final String EXTRA_DATA_FIELD = "extraData";
public static String getExtraDataAsJson(@Nullable ReadableMap metadata) {
if (metadata == null || metadata.getType(EXTRA_DATA_FIELD) == ReadableType.Null) {
return null;
}
try {
Writer extraDataWriter = new StringWriter();
JsonWriter json = new JsonWriter(extraDataWriter);
JsonWriterHelper.value(json, metadata.getDynamic(EXTRA_DATA_FIELD));
json.close();
extraDataWriter.close();
return extraDataWriter.toString();
} catch (IOException ex) {
}
return null;
}
}