Jackson2ObjectMapperBuilder/FactoryBean accepts deserializers by handled type
Issue: SPR-14337
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<ObjectMapper
|
||||
|
||||
/**
|
||||
* 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 #setSerializersByType(Map)
|
||||
*/
|
||||
public void setSerializers(JsonSerializer<?>... serializers) {
|
||||
@@ -272,6 +271,16 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||
this.builder.serializersByType(serializers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 #setDeserializersByType(Map)
|
||||
*/
|
||||
public void setDeserializers(JsonDeserializer<?>... deserializers) {
|
||||
this.builder.deserializers(deserializers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure custom deserializers for the given types.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user