Source:
public void testDeserializationMissingNode() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode root = objectMapper.createObjectNode(); root.put("id", 123123123); byte[] serializedJson = objectMapper.writeValueAsBytes(root); DataType dataType = ROW(FIELD("name", STRING())); RowType schema = (RowType) dataType.getLogicalType(); JsonRowDataDeserializationSchema deserializationSchema = new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), false, false, TimestampFormat.ISO_8601); Row expected = new Row(1); Row actual = convertToExternal(deserializationSchema.deserialize(serializedJson), dataType); assertEquals(expected, actual); deserializationSchema = deserializationSchema = new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), true, false, TimestampFormat.ISO_8601); String errorMessage = "Failed to deserialize JSON '{\"id\":123123123}'."; try { deserializationSchema.deserialize(serializedJson); throw new RuntimeException("expecting exception message: " + errorMessage); } catch (Throwable t) { assertEquals(errorMessage, t.getMessage()); } deserializationSchema = new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), false, true, TimestampFormat.ISO_8601); actual = convertToExternal(deserializationSchema.deserialize(serializedJson), dataType); assertEquals(expected, actual); errorMessage = "JSON format doesn't support failOnMissingField and ignoreParseErrors are both enabled."; try { new JsonRowDataDeserializationSchema( schema, new RowDataTypeInfo(schema), true, true, TimestampFormat.ISO_8601); throw new RuntimeException("expecting exception message: " + errorMessage); } catch (Throwable t) { assertEquals(errorMessage, t.getMessage()); } }

Target:
public void testDeserializationMissingNode() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode root = objectMapper.createObjectNode(); root.put("id", 123123123); byte[] serializedJson = objectMapper.writeValueAsBytes(root); DataType dataType = ROW(FIELD("name", STRING())); RowType schema = (RowType) dataType.getLogicalType(); JsonRowDataDeserializationSchema deserializationSchema = new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), false, false, TimestampFormat.ISO_8601); Row expected = new Row(1); Row actual = convertToExternal(deserializationSchema.deserialize(serializedJson), dataType); assertEquals(expected, actual); deserializationSchema = deserializationSchema = new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), true, false, TimestampFormat.ISO_8601); String errorMessage = "Failed to deserialize JSON '{\"id\":123123123}'."; try { deserializationSchema.deserialize(serializedJson); Assert.fail("expecting exception message: " + errorMessage); } catch (Throwable t) { assertEquals(errorMessage, t.getMessage()); } deserializationSchema = new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), false, true, TimestampFormat.ISO_8601); actual = convertToExternal(deserializationSchema.deserialize(serializedJson), dataType); assertEquals(expected, actual); errorMessage = "JSON format doesn't support failOnMissingField and ignoreParseErrors are both enabled."; try { new JsonRowDataDeserializationSchema( schema, WrapperTypeInfo.of(schema), true, true, TimestampFormat.ISO_8601); Assert.fail("expecting exception message: " + errorMessage); } catch (Throwable t) { assertEquals(errorMessage, t.getMessage()); } }