Require Jackson 2.6+, FreeMarker 2.3.21+, XStream 1.4.5+
Issue: SPR-13062
This commit is contained in:
@@ -48,7 +48,7 @@ import org.springframework.util.TypeUtils;
|
||||
* Abstract base class for Jackson based and content type independent
|
||||
* {@link HttpMessageConverter} implementations.
|
||||
*
|
||||
* <p>Compatible with Jackson 2.1 and higher.
|
||||
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Keith Donald
|
||||
@@ -62,14 +62,6 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
// Check for Jackson 2.3's overloaded canDeserialize/canSerialize variants with cause reference
|
||||
private static final boolean jackson23Available = ClassUtils.hasMethod(ObjectMapper.class,
|
||||
"canDeserialize", JavaType.class, AtomicReference.class);
|
||||
|
||||
// Check for Jackson 2.6+ for support of generic type aware serialization of polymorphic collections
|
||||
private static final boolean jackson26Available = ClassUtils.hasMethod(ObjectMapper.class,
|
||||
"setDefaultPrettyPrinter", PrettyPrinter.class);
|
||||
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
@@ -144,7 +136,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
@Override
|
||||
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
|
||||
JavaType javaType = getJavaType(type, contextClass);
|
||||
if (!jackson23Available || !logger.isWarnEnabled()) {
|
||||
if (!logger.isWarnEnabled()) {
|
||||
return (this.objectMapper.canDeserialize(javaType) && canRead(mediaType));
|
||||
}
|
||||
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
|
||||
@@ -166,7 +158,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
||||
if (!jackson23Available || !logger.isWarnEnabled()) {
|
||||
if (!logger.isWarnEnabled()) {
|
||||
return (this.objectMapper.canSerialize(clazz) && canWrite(mediaType));
|
||||
}
|
||||
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
|
||||
@@ -208,13 +200,12 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
return readJavaType(javaType, inputMessage);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
|
||||
try {
|
||||
if (inputMessage instanceof MappingJacksonInputMessage) {
|
||||
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
|
||||
if (deserializationView != null) {
|
||||
return this.objectMapper.readerWithView(deserializationView).withType(javaType).
|
||||
return this.objectMapper.readerWithView(deserializationView).forType(javaType).
|
||||
readValue(inputMessage.getBody());
|
||||
}
|
||||
}
|
||||
@@ -226,7 +217,6 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
@@ -245,7 +235,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
serializationView = container.getSerializationView();
|
||||
filters = container.getFilters();
|
||||
}
|
||||
if (jackson26Available && type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) {
|
||||
if (type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) {
|
||||
javaType = getJavaType(type, null);
|
||||
}
|
||||
ObjectWriter objectWriter;
|
||||
@@ -259,7 +249,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
objectWriter = this.objectMapper.writer();
|
||||
}
|
||||
if (javaType != null && javaType.isContainerType()) {
|
||||
objectWriter = objectWriter.withType(javaType);
|
||||
objectWriter = objectWriter.forType(javaType);
|
||||
}
|
||||
objectWriter.writeValue(generator, value);
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ import org.springframework.util.StringUtils;
|
||||
* <li><a href="https://github.com/FasterXML/jackson-datatype-joda">jackson-datatype-joda</a>: support for Joda-Time types</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Tested against Jackson 2.4, 2.5, 2.6; compatible with Jackson 2.0 and higher.
|
||||
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Juergen Hoeller
|
||||
@@ -561,7 +561,6 @@ public class Jackson2ObjectMapperBuilder {
|
||||
* settings. This can be applied to any number of {@code ObjectMappers}.
|
||||
* @param objectMapper the ObjectMapper to configure
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void configure(ObjectMapper objectMapper) {
|
||||
Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
||||
|
||||
@@ -609,13 +608,11 @@ public class Jackson2ObjectMapperBuilder {
|
||||
}
|
||||
|
||||
if (this.filters != null) {
|
||||
// Deprecated as of Jackson 2.6, but just in favor of a fluent variant.
|
||||
objectMapper.setFilters(this.filters);
|
||||
objectMapper.setFilterProvider(this.filters);
|
||||
}
|
||||
|
||||
for (Class<?> target : this.mixIns.keySet()) {
|
||||
// Deprecated as of Jackson 2.5, but just in favor of a fluent variant.
|
||||
objectMapper.addMixInAnnotations(target, this.mixIns.get(target));
|
||||
objectMapper.addMixIn(target, this.mixIns.get(target));
|
||||
}
|
||||
|
||||
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
|
||||
@@ -720,15 +717,7 @@ public class Jackson2ObjectMapperBuilder {
|
||||
objectMapper.registerModule(BeanUtils.instantiate(javaTimeModule));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// jackson-datatype-jsr310 not available or older than 2.6
|
||||
try {
|
||||
Class<? extends Module> jsr310Module = (Class<? extends Module>)
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jsr310.JSR310Module", this.moduleClassLoader);
|
||||
objectMapper.registerModule(BeanUtils.instantiate(jsr310Module));
|
||||
}
|
||||
catch (ClassNotFoundException ex2) {
|
||||
// OK, jackson-datatype-jsr310 not available at all...
|
||||
}
|
||||
// jackson-datatype-jsr310 not available
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
* </bean
|
||||
* </pre>
|
||||
*
|
||||
* <p>Tested against Jackson 2.4, 2.5, 2.6; compatible with Jackson 2.0 and higher.
|
||||
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
|
||||
*
|
||||
* @author <a href="mailto:dmitry.katsubo@gmail.com">Dmitry Katsubo</a>
|
||||
* @author Rossen Stoyanchev
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -35,7 +35,7 @@ import org.springframework.http.MediaType;
|
||||
*
|
||||
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
|
||||
*
|
||||
* <p>Compatible with Jackson 2.1 and higher.
|
||||
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Keith Donald
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
|
||||
*
|
||||
* <p>Compatible with Jackson 2.1 and higher.
|
||||
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.1
|
||||
@@ -72,4 +72,5 @@ public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2Http
|
||||
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
|
||||
super.setObjectMapper(objectMapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user