|
1 | 1 | /* |
2 | | - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -284,8 +284,7 @@ public Jackson2ObjectMapperBuilder mixIns(Map<Class<?>, Class<?>> mixIns) { |
284 | 284 |
|
285 | 285 | /** |
286 | 286 | * Configure custom serializers. Each serializer is registered for the type |
287 | | - * returned by {@link JsonSerializer#handledType()}, which must not be |
288 | | - * {@code null}. |
| 287 | + * returned by {@link JsonSerializer#handledType()}, which must not be {@code null}. |
289 | 288 | * @see #serializersByType(Map) |
290 | 289 | */ |
291 | 290 | public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) { |
@@ -324,6 +323,25 @@ public Jackson2ObjectMapperBuilder serializersByType(Map<Class<?>, JsonSerialize |
324 | 323 | return this; |
325 | 324 | } |
326 | 325 |
|
| 326 | + /** |
| 327 | + * Configure custom deserializers. Each deserializer is registered for the type |
| 328 | + * returned by {@link JsonDeserializer#handledType()}, which must not be {@code null}. |
| 329 | + * @since 4.3 |
| 330 | + * @see #deserializersByType(Map) |
| 331 | + */ |
| 332 | + public Jackson2ObjectMapperBuilder deserializers(JsonDeserializer<?>... deserializers) { |
| 333 | + if (deserializers != null) { |
| 334 | + for (JsonDeserializer<?> deserializer : deserializers) { |
| 335 | + Class<?> handledType = deserializer.handledType(); |
| 336 | + if (handledType == null || handledType == Object.class) { |
| 337 | + throw new IllegalArgumentException("Unknown handled type in " + deserializer.getClass().getName()); |
| 338 | + } |
| 339 | + this.deserializers.put(deserializer.handledType(), deserializer); |
| 340 | + } |
| 341 | + } |
| 342 | + return this; |
| 343 | + } |
| 344 | + |
327 | 345 | /** |
328 | 346 | * Configure a custom deserializer for the given type. |
329 | 347 | * @since 4.1.2 |
|
0 commit comments