|
| 1 | +/* |
| 2 | + * Copyright 2012-2020 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.autoconfigure.jackson; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | + |
| 22 | +import org.springframework.boot.testsupport.classpath.ClassPathExclusions; |
| 23 | +import org.springframework.boot.testsupport.classpath.ClassPathOverrides; |
| 24 | + |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; |
| 26 | + |
| 27 | +/** |
| 28 | + * Tests for {@link JacksonAutoConfiguration} using Jackson 2.11.x |
| 29 | + * |
| 30 | + * @author Stephane Nicoll |
| 31 | + */ |
| 32 | +@ClassPathExclusions({ "jackson-databind*.jar", "jackson-dataformat-xml*.jar" }) |
| 33 | +@ClassPathOverrides({ "com.fasterxml.jackson.core:jackson-databind:2.11.3", |
| 34 | + "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.3" }) |
| 35 | +public class Jackson211AutoConfigurationTests extends JacksonAutoConfigurationTests { |
| 36 | + |
| 37 | + public static final String STRATEGY_CLASS_NAME = "com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy"; |
| 38 | + |
| 39 | + @Test |
| 40 | + void customPropertyNamingStrategyField() { |
| 41 | + this.contextRunner.withPropertyValues("spring.jackson.property-naming-strategy:SNAKE_CASE").run((context) -> { |
| 42 | + ObjectMapper mapper = context.getBean(ObjectMapper.class); |
| 43 | + assertThat(mapper.getPropertyNamingStrategy().getClass().getName()).isEqualTo(STRATEGY_CLASS_NAME); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void customPropertyNamingStrategyClass() { |
| 49 | + this.contextRunner.withPropertyValues( |
| 50 | + "spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy") |
| 51 | + .run((context) -> { |
| 52 | + ObjectMapper mapper = context.getBean(ObjectMapper.class); |
| 53 | + assertThat(mapper.getPropertyNamingStrategy().getClass().getName()).isEqualTo(STRATEGY_CLASS_NAME); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments