Avoid outdated Jackson API in tests

See gh-25907
This commit is contained in:
Juergen Hoeller
2020-10-13 11:13:54 +02:00
parent a29929db5b
commit 94d330695f
3 changed files with 13 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -348,7 +348,7 @@ public class Jackson2ObjectMapperBuilderTests {
@Test
public void propertyNamingStrategy() {
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().propertyNamingStrategy(strategy).build();
assertSame(strategy, objectMapper.getSerializationConfig().getPropertyNamingStrategy());
assertSame(strategy, objectMapper.getDeserializationConfig().getPropertyNamingStrategy());
@@ -436,7 +436,7 @@ public class Jackson2ObjectMapperBuilderTests {
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.modules(new ArrayList<>()) // Disable well-known modules detection
.serializers(serializer1)
.serializersByType(Collections.singletonMap(Boolean.class, serializer2))
.deserializersByType(deserializerMap)
@@ -617,6 +617,7 @@ public class Jackson2ObjectMapperBuilderTests {
}
}
public static class JacksonVisibilityBean {
private String property1;
@@ -626,9 +627,9 @@ public class Jackson2ObjectMapperBuilderTests {
public String getProperty3() {
return null;
}
}
static class OffsetDateTimeDeserializer extends JsonDeserializer<OffsetDateTime> {
private static final String CURRENT_ZONE_OFFSET = OffsetDateTime.now().getOffset().toString();
@@ -648,6 +649,7 @@ public class Jackson2ObjectMapperBuilderTests {
}
}
@JsonDeserialize
static class DemoPojo {
@@ -660,9 +662,9 @@ public class Jackson2ObjectMapperBuilderTests {
public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
this.offsetDateTime = offsetDateTime;
}
}
static class Foo {}
static class Bar {}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 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.
@@ -213,8 +213,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
assertEquals(timestamp.toString(), new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8"));
}
@Test // SPR-12634
@SuppressWarnings("unchecked")
@Test // SPR-12634
public void customizeDefaultModulesWithModuleClass() throws JsonProcessingException, UnsupportedEncodingException {
this.factory.setModulesToInstall(CustomIntegerModule.class);
this.factory.afterPropertiesSet();
@@ -225,7 +224,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
assertThat(new String(objectMapper.writeValueAsBytes(new Integer(4)), "UTF-8"), containsString("customid"));
}
@Test // SPR-12634
@Test // SPR-12634
public void customizeDefaultModulesWithSerializer() throws JsonProcessingException, UnsupportedEncodingException {
Map<Class<?>, JsonSerializer<?>> serializers = new HashMap<>();
serializers.put(Integer.class, new CustomIntegerSerializer());
@@ -263,7 +262,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
@Test
public void propertyNamingStrategy() {
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
this.factory.setPropertyNamingStrategy(strategy);
this.factory.afterPropertiesSet();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2020 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.
@@ -46,7 +46,6 @@ import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.junit.Before;
import org.junit.Test;
@@ -202,11 +201,6 @@ public class SpringHandlerInstantiatorTests {
return JsonTypeInfo.Id.CUSTOM;
}
// Only needed when compiling against Jackson 2.7; gone in 2.8
public JavaType typeFromId(String s) {
return TypeFactory.defaultInstance().constructFromCanonical(s);
}
@Override
public String idFromValue(Object value) {
isAutowiredFiledInitialized = (this.capitalizer != null);
@@ -227,7 +221,7 @@ public class SpringHandlerInstantiatorTests {
return null;
}
// New in Jackson 2.7
@Override
public String getDescForKnownTypeIds() {
return null;
}