mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove JsonWriter, support bridge types in JsonWriterHelper
Summary: @public * Removes `JsonWriter`; it's apparently a buggy fork of [`android.util.JsonWriter`](https://developer.android.com/reference/android/util/JsonWriter) which has existed since API level 11. Our version doesn't insert commas before objects or arrays within an array. Instead of fixing it, we can just use the Android one. * Extends `JsonWriterHelper` to support serialising `ReadableMap`, `ReadableArray` and `Dynamic` values into a `JsonWriter`. Reviewed By: kathryngray Differential Revision: D16131713 fbshipit-source-id: d258af42b669f10218cae8b086e7adc3226d16c0
This commit is contained in:
committed by
Facebook Github Bot
parent
a269c1f6c2
commit
e0ae655787
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* <p>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.bridge;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JsonWriterTest {
|
||||
private final StringWriter mStringWriter;
|
||||
private final JsonWriter mWriter;
|
||||
|
||||
public JsonWriterTest() {
|
||||
mStringWriter = new StringWriter();
|
||||
mWriter = new JsonWriter(mStringWriter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyObject() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.endObject();
|
||||
verify("{}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyNestedObject() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.beginObject();
|
||||
mWriter.endObject();
|
||||
mWriter.endObject();
|
||||
verify("{{}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyArray() throws IOException {
|
||||
mWriter.beginArray();
|
||||
mWriter.endArray();
|
||||
verify("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyNestedArray() throws IOException {
|
||||
mWriter.beginArray();
|
||||
mWriter.beginArray();
|
||||
mWriter.endArray();
|
||||
mWriter.endArray();
|
||||
verify("[[]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallObject() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.name("hello").value(true);
|
||||
mWriter.name("hello_again").value("hi!");
|
||||
mWriter.endObject();
|
||||
verify("{\"hello\":true,\"hello_again\":\"hi!\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallArray() throws IOException {
|
||||
mWriter.beginArray();
|
||||
mWriter.value(true);
|
||||
mWriter.value(1);
|
||||
mWriter.value(1.0);
|
||||
mWriter.value("hi!");
|
||||
mWriter.endArray();
|
||||
verify("[true,1,1.0,\"hi!\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void string() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.name("string").value("hello!");
|
||||
mWriter.endObject();
|
||||
verify("{\"string\":\"hello!\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complexString() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.name("string").value("\t\uD83D\uDCA9");
|
||||
mWriter.endObject();
|
||||
verify("{\"string\":\"\\t\uD83D\uDCA9\"}");
|
||||
}
|
||||
|
||||
private void verify(String expected) throws IOException {
|
||||
mWriter.close();
|
||||
assertThat(mStringWriter.getBuffer().toString()).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user