|
| 1 | +package com.fasterxml.jackson.module.paramnames; |
| 2 | + |
| 3 | +import static org.assertj.core.api.BDDAssertions.then; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.*; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.databind.*; |
| 8 | + |
| 9 | +import org.junit.Test; |
| 10 | + |
| 11 | +// for [java8-modules#74] |
| 12 | +public class CreatorWithNamingStrategy74Test |
| 13 | + extends ModuleTestBase |
| 14 | +{ |
| 15 | + static class ClassWithTwoProperties { |
| 16 | + public final int a; |
| 17 | + public final int b; |
| 18 | + |
| 19 | + public ClassWithTwoProperties(@JsonProperty("a") int a, @JsonProperty("b") int b) { |
| 20 | + this.a = a; |
| 21 | + this.b = b; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testPrivateConstructorWithAnnotations() throws Exception { |
| 27 | + verifyObjectDeserializationWithNamingStrategy( |
| 28 | + PropertyNamingStrategy.SNAKE_CASE, |
| 29 | + "{\"a\":1, \"b\": 2}", |
| 30 | + new ClassWithTwoProperties(1, 2)); |
| 31 | + } |
| 32 | + |
| 33 | + private void verifyObjectDeserializationWithNamingStrategy( |
| 34 | + final PropertyNamingStrategy propertyNamingStrategy, final String json, Object expected) |
| 35 | + throws Exception { |
| 36 | + // given |
| 37 | + ObjectMapper objectMapper = newMapper() |
| 38 | + .setPropertyNamingStrategy(propertyNamingStrategy) |
| 39 | + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) |
| 40 | + .setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY) |
| 41 | + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); |
| 42 | + |
| 43 | + // when |
| 44 | + Object actual = objectMapper.readValue(json, expected.getClass()); |
| 45 | + |
| 46 | + then(actual).isEqualToComparingFieldByField(expected); |
| 47 | + } |
| 48 | +} |
0 commit comments