Skip to content

Commit 8ce5e88

Browse files
committed
Require Jackson 2.6+, FreeMarker 2.3.21+, XStream 1.4.5+
Issue: SPR-13062
1 parent db05f43 commit 8ce5e88

File tree

14 files changed

+55
-89
lines changed

14 files changed

+55
-89
lines changed

spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -316,12 +316,8 @@ public Configuration createConfiguration() throws IOException, TemplateException
316316
* @throws TemplateException on FreeMarker initialization failure
317317
* @see #createConfiguration()
318318
*/
319-
@SuppressWarnings("deprecation")
320319
protected Configuration newConfiguration() throws IOException, TemplateException {
321-
// The default Configuration constructor is deprecated as of FreeMarker 2.3.21,
322-
// in favor of specifying a compatibility version - which is a 2.3.21 feature.
323-
// We won't be able to call that for a long while, but custom subclasses can.
324-
return new Configuration();
320+
return new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
325321
}
326322

327323
/**

spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -50,7 +50,7 @@
5050
* <li>{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled</li>
5151
* </ul>
5252
*
53-
* <p>Tested against Jackson 2.2; compatible with Jackson 2.0 and higher.
53+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
5454
*
5555
* @author Mark Pollack
5656
* @author Dave Syer

spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* <li>{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled</li>
5151
* </ul>
5252
*
53-
* <p>Compatible with Jackson 2.1 and higher.
53+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
5454
*
5555
* @author Rossen Stoyanchev
5656
* @author Juergen Hoeller
@@ -59,11 +59,6 @@
5959
*/
6060
public class MappingJackson2MessageConverter extends AbstractMessageConverter {
6161

62-
// Check for Jackson 2.3's overloaded canDeserialize/canSerialize variants with cause reference
63-
private static final boolean jackson23Available =
64-
ClassUtils.hasMethod(ObjectMapper.class, "canDeserialize", JavaType.class, AtomicReference.class);
65-
66-
6762
private ObjectMapper objectMapper;
6863

6964
private Boolean prettyPrint;
@@ -146,7 +141,7 @@ protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
146141
return false;
147142
}
148143
JavaType javaType = this.objectMapper.constructType(targetClass);
149-
if (!jackson23Available || !logger.isWarnEnabled()) {
144+
if (!logger.isWarnEnabled()) {
150145
return (this.objectMapper.canDeserialize(javaType) && supportsMimeType(message.getHeaders()));
151146
}
152147
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
@@ -168,7 +163,7 @@ protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
168163

169164
@Override
170165
protected boolean canConvertTo(Object payload, MessageHeaders headers) {
171-
if (!jackson23Available || !logger.isWarnEnabled()) {
166+
if (!logger.isWarnEnabled()) {
172167
return (this.objectMapper.canSerialize(payload.getClass()) && supportsMimeType(headers));
173168
}
174169
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
@@ -195,7 +190,6 @@ protected boolean supports(Class<?> clazz) {
195190
}
196191

197192
@Override
198-
@SuppressWarnings("deprecation")
199193
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) {
200194
JavaType javaType = this.objectMapper.constructType(targetClass);
201195
Object payload = message.getPayload();
@@ -204,15 +198,15 @@ protected Object convertFromInternal(Message<?> message, Class<?> targetClass, O
204198
try {
205199
if (payload instanceof byte[]) {
206200
if (view != null) {
207-
return this.objectMapper.readerWithView(view).withType(javaType).readValue((byte[]) payload);
201+
return this.objectMapper.readerWithView(view).forType(javaType).readValue((byte[]) payload);
208202
}
209203
else {
210204
return this.objectMapper.readValue((byte[]) payload, javaType);
211205
}
212206
}
213207
else {
214208
if (view != null) {
215-
return this.objectMapper.readerWithView(view).withType(javaType).readValue(payload.toString());
209+
return this.objectMapper.readerWithView(view).forType(javaType).readValue(payload.toString());
216210
}
217211
else {
218212
return this.objectMapper.readValue(payload.toString(), javaType);

spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -44,6 +44,7 @@
4444
import com.thoughtworks.xstream.converters.DataHolder;
4545
import com.thoughtworks.xstream.converters.SingleValueConverter;
4646
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
47+
import com.thoughtworks.xstream.core.ClassLoaderReference;
4748
import com.thoughtworks.xstream.core.DefaultConverterLookup;
4849
import com.thoughtworks.xstream.core.util.CompositeClassLoader;
4950
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
@@ -104,7 +105,7 @@
104105
* Therefore, it has limited namespace support. As such, it is rather unsuitable for
105106
* usage within Web Services.
106107
*
107-
* <p>This marshaller requires XStream 1.4 or higher, as of Spring 4.0.
108+
* <p>This marshaller requires XStream 1.4.5 or higher, as of Spring 4.3.
108109
* Note that {@link XStream} construction has been reworked in 4.0, with the
109110
* stream driver and the class loader getting passed into XStream itself now.
110111
*
@@ -405,12 +406,9 @@ protected XStream buildXStream() {
405406
* standard constructors or creating a custom subclass.
406407
* @return the {@code XStream} instance
407408
*/
408-
@SuppressWarnings("deprecation")
409409
protected XStream constructXStream() {
410-
// The referenced XStream constructor has been deprecated as of 1.4.5.
411-
// We're preserving this call for broader XStream 1.4.x compatibility.
412-
return new XStream(this.reflectionProvider, getDefaultDriver(),
413-
this.beanClassLoader, this.mapper, this.converterLookup, this.converterRegistry) {
410+
return new XStream(this.reflectionProvider, getDefaultDriver(), new ClassLoaderReference(this.beanClassLoader),
411+
this.mapper, this.converterLookup, this.converterRegistry) {
414412
@Override
415413
protected MapperWrapper wrapMapper(MapperWrapper next) {
416414
MapperWrapper mapperToWrap = next;

spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* Abstract base class for Jackson based and content type independent
4949
* {@link HttpMessageConverter} implementations.
5050
*
51-
* <p>Compatible with Jackson 2.1 and higher.
51+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
5252
*
5353
* @author Arjen Poutsma
5454
* @author Keith Donald
@@ -62,14 +62,6 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
6262

6363
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
6464

65-
// Check for Jackson 2.3's overloaded canDeserialize/canSerialize variants with cause reference
66-
private static final boolean jackson23Available = ClassUtils.hasMethod(ObjectMapper.class,
67-
"canDeserialize", JavaType.class, AtomicReference.class);
68-
69-
// Check for Jackson 2.6+ for support of generic type aware serialization of polymorphic collections
70-
private static final boolean jackson26Available = ClassUtils.hasMethod(ObjectMapper.class,
71-
"setDefaultPrettyPrinter", PrettyPrinter.class);
72-
7365

7466
protected ObjectMapper objectMapper;
7567

@@ -144,7 +136,7 @@ public boolean canRead(Class<?> clazz, MediaType mediaType) {
144136
@Override
145137
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
146138
JavaType javaType = getJavaType(type, contextClass);
147-
if (!jackson23Available || !logger.isWarnEnabled()) {
139+
if (!logger.isWarnEnabled()) {
148140
return (this.objectMapper.canDeserialize(javaType) && canRead(mediaType));
149141
}
150142
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
@@ -166,7 +158,7 @@ public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
166158

167159
@Override
168160
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
169-
if (!jackson23Available || !logger.isWarnEnabled()) {
161+
if (!logger.isWarnEnabled()) {
170162
return (this.objectMapper.canSerialize(clazz) && canWrite(mediaType));
171163
}
172164
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
@@ -208,13 +200,12 @@ public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessa
208200
return readJavaType(javaType, inputMessage);
209201
}
210202

211-
@SuppressWarnings("deprecation")
212203
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
213204
try {
214205
if (inputMessage instanceof MappingJacksonInputMessage) {
215206
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
216207
if (deserializationView != null) {
217-
return this.objectMapper.readerWithView(deserializationView).withType(javaType).
208+
return this.objectMapper.readerWithView(deserializationView).forType(javaType).
218209
readValue(inputMessage.getBody());
219210
}
220211
}
@@ -226,7 +217,6 @@ private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
226217
}
227218

228219
@Override
229-
@SuppressWarnings("deprecation")
230220
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
231221
throws IOException, HttpMessageNotWritableException {
232222

@@ -245,7 +235,7 @@ protected void writeInternal(Object object, Type type, HttpOutputMessage outputM
245235
serializationView = container.getSerializationView();
246236
filters = container.getFilters();
247237
}
248-
if (jackson26Available && type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) {
238+
if (type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) {
249239
javaType = getJavaType(type, null);
250240
}
251241
ObjectWriter objectWriter;
@@ -259,7 +249,7 @@ else if (filters != null) {
259249
objectWriter = this.objectMapper.writer();
260250
}
261251
if (javaType != null && javaType.isContainerType()) {
262-
objectWriter = objectWriter.withType(javaType);
252+
objectWriter = objectWriter.forType(javaType);
263253
}
264254
objectWriter.writeValue(generator, value);
265255

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
* <li><a href="https://github.com/FasterXML/jackson-datatype-joda">jackson-datatype-joda</a>: support for Joda-Time types</li>
7676
* </ul>
7777
*
78-
* <p>Tested against Jackson 2.4, 2.5, 2.6; compatible with Jackson 2.0 and higher.
78+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
7979
*
8080
* @author Sebastien Deleuze
8181
* @author Juergen Hoeller
@@ -561,7 +561,6 @@ public <T extends ObjectMapper> T build() {
561561
* settings. This can be applied to any number of {@code ObjectMappers}.
562562
* @param objectMapper the ObjectMapper to configure
563563
*/
564-
@SuppressWarnings("deprecation")
565564
public void configure(ObjectMapper objectMapper) {
566565
Assert.notNull(objectMapper, "ObjectMapper must not be null");
567566

@@ -609,13 +608,11 @@ else if (this.findWellKnownModules) {
609608
}
610609

611610
if (this.filters != null) {
612-
// Deprecated as of Jackson 2.6, but just in favor of a fluent variant.
613-
objectMapper.setFilters(this.filters);
611+
objectMapper.setFilterProvider(this.filters);
614612
}
615613

616614
for (Class<?> target : this.mixIns.keySet()) {
617-
// Deprecated as of Jackson 2.5, but just in favor of a fluent variant.
618-
objectMapper.addMixInAnnotations(target, this.mixIns.get(target));
615+
objectMapper.addMixIn(target, this.mixIns.get(target));
619616
}
620617

621618
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
@@ -720,15 +717,7 @@ private void registerWellKnownModulesIfAvailable(ObjectMapper objectMapper) {
720717
objectMapper.registerModule(BeanUtils.instantiate(javaTimeModule));
721718
}
722719
catch (ClassNotFoundException ex) {
723-
// jackson-datatype-jsr310 not available or older than 2.6
724-
try {
725-
Class<? extends Module> jsr310Module = (Class<? extends Module>)
726-
ClassUtils.forName("com.fasterxml.jackson.datatype.jsr310.JSR310Module", this.moduleClassLoader);
727-
objectMapper.registerModule(BeanUtils.instantiate(jsr310Module));
728-
}
729-
catch (ClassNotFoundException ex2) {
730-
// OK, jackson-datatype-jsr310 not available at all...
731-
}
720+
// jackson-datatype-jsr310 not available
732721
}
733722
}
734723

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
* &lt;/bean
128128
* </pre>
129129
*
130-
* <p>Tested against Jackson 2.4, 2.5, 2.6; compatible with Jackson 2.0 and higher.
130+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
131131
*
132132
* @author <a href="mailto:[email protected]">Dmitry Katsubo</a>
133133
* @author Rossen Stoyanchev

spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -35,7 +35,7 @@
3535
*
3636
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
3737
*
38-
* <p>Compatible with Jackson 2.1 and higher.
38+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
3939
*
4040
* @author Arjen Poutsma
4141
* @author Keith Donald

spring-web/src/main/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -35,7 +35,7 @@
3535
*
3636
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
3737
*
38-
* <p>Compatible with Jackson 2.1 and higher.
38+
* <p>Compatible with Jackson 2.6 and higher, as of Spring 4.3.
3939
*
4040
* @author Sebastien Deleuze
4141
* @since 4.1
@@ -72,4 +72,5 @@ public void setObjectMapper(ObjectMapper objectMapper) {
7272
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
7373
super.setObjectMapper(objectMapper);
7474
}
75+
7576
}

spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import freemarker.ext.servlet.HttpSessionHashModel;
4343
import freemarker.ext.servlet.ServletContextHashModel;
4444
import freemarker.template.Configuration;
45+
import freemarker.template.DefaultObjectWrapperBuilder;
4546
import freemarker.template.ObjectWrapper;
4647
import freemarker.template.SimpleHash;
4748
import freemarker.template.Template;
@@ -186,10 +187,10 @@ protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
186187
* {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
187188
* @see freemarker.template.Configuration#getObjectWrapper()
188189
*/
189-
@SuppressWarnings("deprecation")
190190
protected ObjectWrapper getObjectWrapper() {
191191
ObjectWrapper ow = getConfiguration().getObjectWrapper();
192-
return (ow != null ? ow : ObjectWrapper.DEFAULT_WRAPPER);
192+
return (ow != null ? ow :
193+
new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build());
193194
}
194195

195196
/**

0 commit comments

Comments
 (0)