Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-8544

JSONKeyValueDeserializationSchema throws NPE when message key is null

    Details

      Description

      JSONKeyValueDeserializationSchema call Jaskon to deserialize the message key without validation.
      If a message with key == null is read, flink throws an NPE.

      	@Override
      	public ObjectNode deserialize(byte[] messageKey, byte[] message, String topic, int partition, long offset) throws IOException {
      		if (mapper == null) {
      			mapper = new ObjectMapper();
      		}
      		ObjectNode node = mapper.createObjectNode();
      		node.set("key", mapper.readValue(messageKey, JsonNode.class)); // messageKey is not validate against null.
      		node.set("value", mapper.readValue(message, JsonNode.class));
      

      The fix is very straightforward.

      		if (messageKey == null) {
      			node.set("key", null)
      		} else {
      			node.set("key", mapper.readValue(messageKey, JsonNode.class));
      		}
      

      If it is appreciated, I would send a pull request.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                billleecn Bill Lee
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified