diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index 9c049eda15c..beee0a4f0f6 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -284,8 +284,7 @@ public class Jackson2ObjectMapperBuilder { /** * Configure custom serializers. Each serializer is registered for the type - * returned by {@link JsonSerializer#handledType()}, which must not be - * {@code null}. + * returned by {@link JsonSerializer#handledType()}, which must not be {@code null}. * @see #serializersByType(Map) */ public Jackson2ObjectMapperBuilder serializers(JsonSerializer... serializers) { @@ -324,6 +323,25 @@ public class Jackson2ObjectMapperBuilder { return this; } + /** + * Configure custom deserializers. Each deserializer is registered for the type + * returned by {@link JsonDeserializer#handledType()}, which must not be {@code null}. + * @since 4.3 + * @see #deserializersByType(Map) + */ + public Jackson2ObjectMapperBuilder deserializers(JsonDeserializer... deserializers) { + if (deserializers != null) { + for (JsonDeserializer deserializer : deserializers) { + Class handledType = deserializer.handledType(); + if (handledType == null || handledType == Object.class) { + throw new IllegalArgumentException("Unknown handled type in " + deserializer.getClass().getName()); + } + this.deserializers.put(deserializer.handledType(), deserializer); + } + } + return this; + } + /** * Configure a custom deserializer for the given type. * @since 4.1.2 diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java index 562ebbb3608..d945a7fb991 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -256,8 +256,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean... serializers) { @@ -272,6 +271,16 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean... deserializers) { + this.builder.deserializers(deserializers); + } + /** * Configure custom deserializers for the given types. */