@@ -680,8 +680,8 @@ else if (listener instanceof MessageListener) {
680680 this .logger .info (this .toString ());
681681 }
682682 Map <String , Object > props = KafkaMessageListenerContainer .this .consumerFactory .getConfigurationProperties ();
683- this .checkNullKeyForExceptions = checkDeserializer (findDeserializerClass (props , false ));
684- this .checkNullValueForExceptions = checkDeserializer (findDeserializerClass (props , true ));
683+ this .checkNullKeyForExceptions = checkDeserializer (findDeserializerClass (props , consumerProperties , false ));
684+ this .checkNullValueForExceptions = checkDeserializer (findDeserializerClass (props , consumerProperties , true ));
685685 this .syncCommitTimeout = determineSyncCommitTimeout ();
686686 if (this .containerProperties .getSyncCommitTimeout () == null ) {
687687 // update the property so we can use it directly from code elsewhere
@@ -846,14 +846,21 @@ else if (timeout instanceof String) {
846846 }
847847 }
848848
849- private Object findDeserializerClass (Map <String , Object > props , boolean isValue ) {
849+ @ Nullable
850+ private Object findDeserializerClass (Map <String , Object > props , Properties consumerOverrides , boolean isValue ) {
850851 Object configuredDeserializer = isValue
851852 ? KafkaMessageListenerContainer .this .consumerFactory .getValueDeserializer ()
852853 : KafkaMessageListenerContainer .this .consumerFactory .getKeyDeserializer ();
853854 if (configuredDeserializer == null ) {
854- return props .get (isValue
855+ Object deser = consumerOverrides .get (isValue
855856 ? ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG
856857 : ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG );
858+ if (deser == null ) {
859+ deser = props .get (isValue
860+ ? ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG
861+ : ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG );
862+ }
863+ return deser ;
857864 }
858865 else {
859866 return configuredDeserializer .getClass ();
@@ -885,10 +892,23 @@ private void subscribeOrAssignTopics(final Consumer<? super K, ? super V> subscr
885892 }
886893 }
887894
888- private boolean checkDeserializer (Object deser ) {
889- return deser instanceof Class
890- ? ErrorHandlingDeserializer2 .class .isAssignableFrom ((Class <?>) deser )
891- : deser instanceof String && deser .equals (ErrorHandlingDeserializer2 .class .getName ());
895+ private boolean checkDeserializer (@ Nullable Object deser ) {
896+ Class <?> deserializer = null ;
897+ if (deser instanceof Class ) {
898+ deserializer = (Class <?>) deser ;
899+ }
900+ else if (deser instanceof String ) {
901+ try {
902+ deserializer = ClassUtils .forName ((String ) deser , getApplicationContext ().getClassLoader ());
903+ }
904+ catch (ClassNotFoundException | LinkageError e ) {
905+ throw new IllegalStateException (e );
906+ }
907+ }
908+ else if (deser != null ) {
909+ throw new IllegalStateException ("Deserializer must be a class or class name, not a " + deser .getClass ());
910+ }
911+ return deserializer == null ? false : ErrorHandlingDeserializer2 .class .isAssignableFrom (deserializer );
892912 }
893913
894914 protected void checkConsumer () {
0 commit comments