Source:
private KafkaConsumer<byte[], byte[]> getKafkaConsumer() { final Map<String, Object> consumerConfigs = KafkaConsumerConfigs.getConsumerProperties(); final Properties props = new Properties(); addConsumerPropertiesFromConfig(props, sortingMapper, consumerProperties); props.putAll(consumerConfigs); ClassLoader currCtxCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Deserializer keyDeserializerObject; Deserializer valueDeserializerObject; try { Class keyDeserializerClass = Class.forName(props.getProperty("key.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer")); Method keyDeserializerMethod = keyDeserializerClass.getMethod("deserialize", String.class, byte[].class); Type keyDeserializerReturnType = keyDeserializerMethod.getGenericReturnType(); if (keyDeserializerReturnType.getTypeName().equals("byte[]")) { keyDeserializerObject = (Deserializer) keyDeserializerClass.getConstructor().newInstance(); } else { throw new IllegalArgumentException("Key deserializer must return a byte array (byte[]), " + keyDeserializerClass.getName() + " returns " + keyDeserializerReturnType.getTypeName()); } } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new StreamException(e); } try { Class valueDeserializerClass = Class.forName(props.getProperty("value.deserializer", "org.apache.kafka.common.serialization.ByteArrayDeserializer")); Method valueDeserializerMethod = valueDeserializerClass.getMethod("deserialize", String.class, byte[].class); Type valueDeserializerReturnType = valueDeserializerMethod.getGenericReturnType(); if (valueDeserializerReturnType.getTypeName().equals("byte[]")) { valueDeserializerObject = (Deserializer) valueDeserializerClass.getConstructor().newInstance(); } else { throw new IllegalArgumentException("Key deserializer must return a byte array (byte[]), " + valueDeserializerClass.getName() + " returns " + valueDeserializerReturnType.getTypeName()); } } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new StreamException(e); } return new KafkaConsumer<>(props, keyDeserializerObject, valueDeserializerObject); } finally { Thread.currentThread().setContextClassLoader(currCtxCl); } }

Target:
private KafkaConsumer<byte[], byte[]> getKafkaConsumer() { final Map<String, Object> consumerConfigs = KafkaConsumerConfigs.getConsumerProperties(); final Properties props = new Properties(); addConsumerPropertiesFromConfig(props, sortingMapper, consumerProperties); props.putAll(consumerConfigs); ClassLoader currCtxCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Deserializer keyDeserializerObject = getKafkaDeserializer(props, "key.deserializer"); Deserializer valueDeserializerObject = getKafkaDeserializer(props, "value.deserializer"); return new KafkaConsumer<>(props, keyDeserializerObject, valueDeserializerObject); } finally { Thread.currentThread().setContextClassLoader(currCtxCl); } }