Skip to content

Commit 7b6293f

Browse files
committed
Avoid outdated Jackson API in tests
See gh-25907
1 parent cd7e5f6 commit 7b6293f

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ private static DeserializerFactoryConfig getDeserializerFactoryConfig(ObjectMapp
355355

356356
@Test
357357
public void propertyNamingStrategy() {
358-
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
358+
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
359359
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().propertyNamingStrategy(strategy).build();
360360
assertThat(objectMapper.getSerializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
361361
assertThat(objectMapper.getDeserializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
@@ -443,7 +443,7 @@ public void completeSetup() throws JsonMappingException {
443443
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
444444

445445
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json()
446-
.modules(new ArrayList<>()) // Disable well-known modules detection
446+
.modules(new ArrayList<>()) // Disable well-known modules detection
447447
.serializers(serializer1)
448448
.serializersByType(Collections.singletonMap(Boolean.class, serializer2))
449449
.deserializersByType(deserializerMap)
@@ -551,7 +551,6 @@ public void factory() {
551551
assertThat(objectMapper.getFactory().getClass()).isEqualTo(SmileFactory.class);
552552
}
553553

554-
555554
@Test
556555
public void visibility() throws JsonProcessingException {
557556
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
@@ -565,6 +564,7 @@ public void visibility() throws JsonProcessingException {
565564
assertThat(json).doesNotContain("property3");
566565
}
567566

567+
568568
public static class CustomIntegerModule extends Module {
569569

570570
@Override
@@ -651,6 +651,7 @@ public void setList(List<T> list) {
651651
}
652652
}
653653

654+
654655
public static class JacksonVisibilityBean {
655656

656657
@SuppressWarnings("unused")
@@ -661,9 +662,9 @@ public static class JacksonVisibilityBean {
661662
public String getProperty3() {
662663
return null;
663664
}
664-
665665
}
666666

667+
667668
static class OffsetDateTimeDeserializer extends JsonDeserializer<OffsetDateTime> {
668669

669670
private static final String CURRENT_ZONE_OFFSET = OffsetDateTime.now().getOffset().toString();
@@ -684,6 +685,7 @@ public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext
684685
}
685686
}
686687

688+
687689
@JsonDeserialize
688690
static class DemoPojo {
689691

@@ -696,13 +698,14 @@ public OffsetDateTime getOffsetDateTime() {
696698
public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
697699
this.offsetDateTime = offsetDateTime;
698700
}
699-
700701
}
701702

703+
702704
@SuppressWarnings("serial")
703705
public static class MyXmlFactory extends XmlFactory {
704706
}
705707

708+
706709
static class Foo {}
707710

708711
static class Bar {}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ public void defaultModules() throws JsonProcessingException, UnsupportedEncoding
212212
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo(timestamp.toString());
213213
}
214214

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

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

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

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

Lines changed: 1 addition & 8 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.
@@ -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.jupiter.api.BeforeEach;
5150
import org.junit.jupiter.api.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,6 @@ public JavaType typeFromId(DatabindContext context, String id) {
227221
return null;
228222
}
229223

230-
// New in Jackson 2.7
231224
@Override
232225
public String getDescForKnownTypeIds() {
233226
return null;

0 commit comments

Comments
 (0)