Remove Jackson dependency

Summary:
This PR removes dependency to Jackson third-party library in Android React Native.

Looking at some older PRs that got merged, it seems like some work had already been done to move away from Jackson.

Anyway, there was only two classes left with a dependency on Jackson. I refactored the code to use android built-in `JsonReader` and `JsonWriter` classes instead.

Prep work was done in https://github.com/facebook/react-native/pull/10516 introducing a few unit tests around serialization, to make sure that refactoring around serialization would not break things.

All references to Jackson in build systems files (BUCK files & build.gradle) have also been removed now that no code depend anymore on this third-party library.

Motivation behind this work is that third-party dependencies in Android React Native can prove to be a pain when trying to integrate React Native components into an already existing large Android application (I know this is not the most common use case for react-native ... yet ;P), that might a
Closes https://github.com/facebook/react-native/pull/10521

Differential Revision: D4226705

Pulled By: mkonicek

fbshipit-source-id: e3a7430a79dd00c871ba3c6a705b0b0c3ec3a701
This commit is contained in:
Benoit Lemaire
2016-11-23 08:49:18 -08:00
committed by Facebook Github Bot
parent e1577df1fd
commit 6fef014295
9 changed files with 119 additions and 135 deletions

View File

@@ -29,8 +29,6 @@ rn_robolectric_test(
react_native_dep('libraries/fbcore/src/test/java/com/facebook/powermock:powermock'),
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
react_native_dep('third-party/java/fest:fest'),
react_native_dep('third-party/java/jackson:core'),
react_native_dep('third-party/java/jackson:jackson'),
react_native_dep('third-party/java/jsr-305:jsr-305'),
react_native_dep('third-party/java/junit:junit'),
react_native_dep('third-party/java/mockito:mockito'),

View File

@@ -92,6 +92,15 @@ public class JSDebuggerWebSocketClientTest {
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
}
@Test
public void test_onMessage_With_Null_ReplyId_ShouldNotTriggerCallbacks() throws Exception {
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":null, \"result\":\"OK\"}"));
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestSuccess", anyInt(), anyString());
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
}
@Test
public void test_onMessage_WithResult_ShouldTriggerRequestSuccess() throws Exception {
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
@@ -101,6 +110,15 @@ public class JSDebuggerWebSocketClientTest {
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
}
@Test
public void test_onMessage_With_Null_Result_ShouldTriggerRequestSuccess() throws Exception {
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"result\":null}"));
PowerMockito.verifyPrivate(client).invoke("triggerRequestSuccess", 0, null);
PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any());
}
@Test
public void test_onMessage_WithError_ShouldCallAbort() throws Exception {
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
@@ -108,4 +126,12 @@ public class JSDebuggerWebSocketClientTest {
client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"error\":\"BOOM\"}"));
PowerMockito.verifyPrivate(client).invoke("abort", eq("BOOM"), isA(JavascriptException.class));
}
@Test
public void test_onMessage_With_Null_Error_ShouldTriggerRequestSuccess() throws Exception {
JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient());
client.onMessage(ResponseBody.create(WebSocket.TEXT, "{\"replyID\":0, \"error\":null}"));
PowerMockito.verifyPrivate(client).invoke("triggerRequestSuccess", anyInt(), anyString());
}
}

View File

@@ -57,6 +57,16 @@ public class JSPackagerWebSocketClientTest {
verify(callback, never()).onMessage(anyString(), anyString());
}
@Test
public void test_onMessage_With_Null_Target_ShouldNotTriggerCallback() throws IOException {
final JSPackagerWebSocketClient.JSPackagerCallback callback =
mock(JSPackagerWebSocketClient.JSPackagerCallback.class);
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"target\": null, \"action\": \"actionValue\"}"));
verify(callback, never()).onMessage(anyString(), anyString());
}
@Test
public void test_onMessage_WithoutAction_ShouldNotTriggerCallback() throws IOException {
final JSPackagerWebSocketClient.JSPackagerCallback callback =
@@ -67,6 +77,16 @@ public class JSPackagerWebSocketClientTest {
verify(callback, never()).onMessage(anyString(), anyString());
}
@Test
public void test_onMessage_With_Null_Action_ShouldNotTriggerCallback() throws IOException {
final JSPackagerWebSocketClient.JSPackagerCallback callback =
mock(JSPackagerWebSocketClient.JSPackagerCallback.class);
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"target\": \"targetValue\", \"action\": null}"));
verify(callback, never()).onMessage(anyString(), anyString());
}
@Test
public void test_onMessage_WrongVersion_ShouldNotTriggerCallback() throws IOException {
final JSPackagerWebSocketClient.JSPackagerCallback callback =