Skip to content

Commit da84155

Browse files
committed
Avoid outdated Jackson API in tests
See gh-25907
1 parent 60a4766 commit da84155

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -352,7 +352,7 @@ private static DeserializerFactoryConfig getDeserializerFactoryConfig(ObjectMapp
352352

353353
@Test
354354
public void propertyNamingStrategy() {
355-
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
355+
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
356356
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().propertyNamingStrategy(strategy).build();
357357
assertSame(strategy, objectMapper.getSerializationConfig().getPropertyNamingStrategy());
358358
assertSame(strategy, objectMapper.getDeserializationConfig().getPropertyNamingStrategy());
@@ -440,7 +440,7 @@ public void completeSetup() throws JsonMappingException {
440440
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
441441

442442
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json()
443-
.modules(new ArrayList<>()) // Disable well-known modules detection
443+
.modules(new ArrayList<>()) // Disable well-known modules detection
444444
.serializers(serializer1)
445445
.serializersByType(Collections.singletonMap(Boolean.class, serializer2))
446446
.deserializersByType(deserializerMap)
@@ -542,7 +542,6 @@ public void factory() {
542542
assertEquals(SmileFactory.class, objectMapper.getFactory().getClass());
543543
}
544544

545-
546545
@Test
547546
public void visibility() throws JsonProcessingException {
548547
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
@@ -556,6 +555,7 @@ public void visibility() throws JsonProcessingException {
556555
assertThat(json, not(containsString("property3")));
557556
}
558557

558+
559559
public static class CustomIntegerModule extends Module {
560560

561561
@Override
@@ -642,6 +642,7 @@ public void setList(List<T> list) {
642642
}
643643
}
644644

645+
645646
public static class JacksonVisibilityBean {
646647

647648
private String property1;
@@ -651,9 +652,9 @@ public static class JacksonVisibilityBean {
651652
public String getProperty3() {
652653
return null;
653654
}
654-
655655
}
656656

657+
657658
static class OffsetDateTimeDeserializer extends JsonDeserializer<OffsetDateTime> {
658659

659660
private static final String CURRENT_ZONE_OFFSET = OffsetDateTime.now().getOffset().toString();
@@ -673,6 +674,7 @@ public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext
673674
}
674675
}
675676

677+
676678
@JsonDeserialize
677679
static class DemoPojo {
678680

@@ -685,13 +687,14 @@ public OffsetDateTime getOffsetDateTime() {
685687
public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
686688
this.offsetDateTime = offsetDateTime;
687689
}
688-
689690
}
690691

692+
691693
@SuppressWarnings("serial")
692694
public static class MyXmlFactory extends XmlFactory {
693695
}
694696

697+
695698
static class Foo {}
696699

697700
static class Bar {}

spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBeanTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -213,8 +213,7 @@ public void defaultModules() throws JsonProcessingException, UnsupportedEncoding
213213
assertEquals(timestamp.toString(), new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8"));
214214
}
215215

216-
@Test // SPR-12634
217-
@SuppressWarnings("unchecked")
216+
@Test // SPR-12634
218217
public void customizeDefaultModulesWithModuleClass() throws JsonProcessingException, UnsupportedEncodingException {
219218
this.factory.setModulesToInstall(CustomIntegerModule.class);
220219
this.factory.afterPropertiesSet();
@@ -225,7 +224,7 @@ public void customizeDefaultModulesWithModuleClass() throws JsonProcessingExcept
225224
assertThat(new String(objectMapper.writeValueAsBytes(new Integer(4)), "UTF-8"), containsString("customid"));
226225
}
227226

228-
@Test // SPR-12634
227+
@Test // SPR-12634
229228
public void customizeDefaultModulesWithSerializer() throws JsonProcessingException, UnsupportedEncodingException {
230229
Map<Class<?>, JsonSerializer<?>> serializers = new HashMap<>();
231230
serializers.put(Integer.class, new CustomIntegerSerializer());
@@ -263,7 +262,7 @@ private static DeserializerFactoryConfig getDeserializerFactoryConfig(ObjectMapp
263262

264263
@Test
265264
public void propertyNamingStrategy() {
266-
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
265+
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
267266
this.factory.setPropertyNamingStrategy(strategy);
268267
this.factory.afterPropertiesSet();
269268

spring-web/src/test/java/org/springframework/http/converter/json/SpringHandlerInstantiatorTests.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -46,7 +46,6 @@
4646
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
4747
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
4848
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
49-
import com.fasterxml.jackson.databind.type.TypeFactory;
5049
import org.junit.Before;
5150
import org.junit.Test;
5251

@@ -202,11 +201,6 @@ public JsonTypeInfo.Id getMechanism() {
202201
return JsonTypeInfo.Id.CUSTOM;
203202
}
204203

205-
// Only needed when compiling against Jackson 2.7; gone in 2.8
206-
public JavaType typeFromId(String s) {
207-
return TypeFactory.defaultInstance().constructFromCanonical(s);
208-
}
209-
210204
@Override
211205
public String idFromValue(Object value) {
212206
isAutowiredFiledInitialized = (this.capitalizer != null);
@@ -227,7 +221,7 @@ public JavaType typeFromId(DatabindContext context, String id) {
227221
return null;
228222
}
229223

230-
// New in Jackson 2.7
224+
@Override
231225
public String getDescForKnownTypeIds() {
232226
return null;
233227
}

0 commit comments

Comments
 (0)