Skip to content

Commit ea0622c

Browse files
committed
Make json parsing a bit loose
1 parent 2b46e75 commit ea0622c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cdt-java-client/src/main/java/com/github/kklisura/cdt/services/impl/ChromeDevToolsServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import com.fasterxml.jackson.annotation.JsonInclude;
24+
import com.fasterxml.jackson.databind.DeserializationFeature;
2425
import com.fasterxml.jackson.databind.JsonNode;
2526
import com.fasterxml.jackson.databind.ObjectMapper;
2627
import com.github.kklisura.cdt.protocol.support.types.EventHandler;
@@ -65,7 +66,9 @@ public abstract class ChromeDevToolsServiceImpl
6566
private static final String PARAMS_PROPERTY = "params";
6667

6768
private static final ObjectMapper OBJECT_MAPPER =
68-
new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
69+
new ObjectMapper()
70+
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
71+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
6972

7073
private WebSocketService webSocketService;
7174

cdt-java-client/src/test/java/com/github/kklisura/cdt/services/impl/ChromeDevToolsServiceImplTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,36 @@ public void testInvokeTestMessageMethod() throws WebSocketServiceException, IOEx
280280
assertEquals(methodInvocation.getParams(), sentInvocation.getParams());
281281
}
282282

283+
@Test
284+
public void testInvokeTestMessageMethodWithUnknownProperty()
285+
throws WebSocketServiceException, IOException {
286+
MethodInvocation methodInvocation = new MethodInvocation();
287+
methodInvocation.setId(1L);
288+
methodInvocation.setMethod("SomeMethod");
289+
methodInvocation.setParams(new HashMap<>());
290+
methodInvocation.getParams().put("param", "value");
291+
292+
Capture<String> messageCapture = Capture.newInstance();
293+
webSocketService.send(capture(messageCapture));
294+
295+
replayAll();
296+
297+
resolveMessage(
298+
"{\"id\":1,\"result\":{\"testProperty\":\"resultValue\",\"testProperty2\":\"resultValue2\",\"unknownProperty\":false}}");
299+
TestMessage testMessage = service.invoke(null, TestMessage.class, methodInvocation);
300+
301+
verifyAll();
302+
303+
assertEquals("resultValue", testMessage.getTestProperty());
304+
assertEquals("resultValue2", testMessage.getTestProperty2());
305+
306+
MethodInvocation sentInvocation =
307+
OBJECT_MAPPER.readerFor(MethodInvocation.class).readValue(messageCapture.getValue());
308+
assertEquals(methodInvocation.getId(), sentInvocation.getId());
309+
assertEquals(methodInvocation.getMethod(), sentInvocation.getMethod());
310+
assertEquals(methodInvocation.getParams(), sentInvocation.getParams());
311+
}
312+
283313
@Test
284314
public void testInvokeTestMessageMethodWithBadJson()
285315
throws WebSocketServiceException, IOException {

0 commit comments

Comments
 (0)