11/*
2- * Copyright 2015-2018 the original author or authors.
2+ * Copyright 2015-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1919import java .io .IOException ;
2020import java .util .Arrays ;
2121import java .util .Map ;
22+ import java .util .function .Consumer ;
2223
2324import org .apache .kafka .common .errors .SerializationException ;
2425import org .apache .kafka .common .header .Headers ;
@@ -144,9 +145,10 @@ public JsonDeserializer(Class<T> targetType) {
144145 * @since 2.2
145146 */
146147 public JsonDeserializer (Class <T > targetType , boolean useHeadersIfPresent ) {
147- this (targetType , new ObjectMapper (), useHeadersIfPresent );
148- this .objectMapper .configure (MapperFeature .DEFAULT_VIEW_INCLUSION , false );
149- this .objectMapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
148+ this (targetType , new ObjectMapper (), useHeadersIfPresent , om -> {
149+ om .configure (MapperFeature .DEFAULT_VIEW_INCLUSION , false );
150+ om .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
151+ });
150152 }
151153
152154 /**
@@ -167,8 +169,14 @@ public JsonDeserializer(Class<T> targetType, ObjectMapper objectMapper) {
167169 * type if not.
168170 * @since 2.2
169171 */
170- @ SuppressWarnings ("unchecked" )
171172 public JsonDeserializer (@ Nullable Class <T > targetType , ObjectMapper objectMapper , boolean useHeadersIfPresent ) {
173+ this (targetType , objectMapper , useHeadersIfPresent , om -> { });
174+ }
175+
176+ @ SuppressWarnings ("unchecked" )
177+ private JsonDeserializer (@ Nullable Class <T > targetType , ObjectMapper objectMapper , boolean useHeadersIfPresent ,
178+ Consumer <ObjectMapper > configurer ) {
179+
172180 Assert .notNull (objectMapper , "'objectMapper' must not be null." );
173181 this .objectMapper = objectMapper ;
174182 this .targetType = targetType ;
@@ -178,6 +186,7 @@ public JsonDeserializer(@Nullable Class<T> targetType, ObjectMapper objectMapper
178186 Assert .isTrue (this .targetType != null || useHeadersIfPresent ,
179187 "'targetType' cannot be null if 'useHeadersIfPresent' is false" );
180188
189+ configurer .accept (this .objectMapper );
181190 if (this .targetType != null ) {
182191 this .reader = this .objectMapper .readerFor (this .targetType );
183192 }
0 commit comments