Polishing
This commit is contained in:
@@ -97,7 +97,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Jackson2ObjectMapperBuilderTests {
|
||||
class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
private static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
|
||||
@@ -105,13 +105,13 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void unknownFeature() {
|
||||
void unknownFeature() {
|
||||
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
|
||||
Jackson2ObjectMapperBuilder.json().featuresToEnable(Boolean.TRUE).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultProperties() {
|
||||
void defaultProperties() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
|
||||
@@ -125,7 +125,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesShortcut() {
|
||||
void propertiesShortcut() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().autoDetectFields(false)
|
||||
.defaultViewInclusion(true).failOnUnknownProperties(true).failOnEmptyBeans(false)
|
||||
.autoDetectGettersSetters(false).indentOutput(true).build();
|
||||
@@ -141,7 +141,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanSetters() {
|
||||
void booleanSetters() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToEnable(MapperFeature.DEFAULT_VIEW_INCLUSION,
|
||||
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
||||
@@ -161,7 +161,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNotNullSerializationInclusion() {
|
||||
void setNotNullSerializationInclusion() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||
assertThat(objectMapper.getSerializationConfig().getSerializationInclusion()).isSameAs(JsonInclude.Include.ALWAYS);
|
||||
objectMapper = Jackson2ObjectMapperBuilder.json().serializationInclusion(JsonInclude.Include.NON_NULL).build();
|
||||
@@ -169,7 +169,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNotDefaultSerializationInclusion() {
|
||||
void setNotDefaultSerializationInclusion() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||
assertThat(objectMapper.getSerializationConfig().getSerializationInclusion()).isSameAs(JsonInclude.Include.ALWAYS);
|
||||
objectMapper = Jackson2ObjectMapperBuilder.json().serializationInclusion(JsonInclude.Include.NON_DEFAULT).build();
|
||||
@@ -177,7 +177,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNotEmptySerializationInclusion() {
|
||||
void setNotEmptySerializationInclusion() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||
assertThat(objectMapper.getSerializationConfig().getSerializationInclusion()).isSameAs(JsonInclude.Include.ALWAYS);
|
||||
objectMapper = Jackson2ObjectMapperBuilder.json().serializationInclusion(JsonInclude.Include.NON_EMPTY).build();
|
||||
@@ -185,7 +185,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateTimeFormatSetter() {
|
||||
void dateTimeFormatSetter() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().dateFormat(dateFormat).build();
|
||||
assertThat(objectMapper.getSerializationConfig().getDateFormat()).isEqualTo(dateFormat);
|
||||
@@ -193,7 +193,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleDateFormatStringSetter() {
|
||||
void simpleDateFormatStringSetter() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().simpleDateFormat(DATE_FORMAT).build();
|
||||
assertThat(objectMapper.getSerializationConfig().getDateFormat()).isEqualTo(dateFormat);
|
||||
@@ -201,14 +201,14 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localeSetter() {
|
||||
void localeSetter() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().locale(Locale.FRENCH).build();
|
||||
assertThat(objectMapper.getSerializationConfig().getLocale()).isEqualTo(Locale.FRENCH);
|
||||
assertThat(objectMapper.getDeserializationConfig().getLocale()).isEqualTo(Locale.FRENCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeZoneSetter() {
|
||||
void timeZoneSetter() {
|
||||
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(timeZone).build();
|
||||
assertThat(objectMapper.getSerializationConfig().getTimeZone()).isEqualTo(timeZone);
|
||||
@@ -216,7 +216,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeZoneStringSetter() {
|
||||
void timeZoneStringSetter() {
|
||||
String zoneId = "Europe/Paris";
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
|
||||
TimeZone timeZone = TimeZone.getTimeZone(zoneId);
|
||||
@@ -225,14 +225,14 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongTimeZoneStringSetter() {
|
||||
void wrongTimeZoneStringSetter() {
|
||||
String zoneId = "foo";
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modules() {
|
||||
void modules() {
|
||||
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(Integer.class, serializer1);
|
||||
@@ -243,7 +243,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void modulesToInstallByClass() {
|
||||
void modulesToInstallByClass() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(CustomIntegerModule.class)
|
||||
.build();
|
||||
@@ -252,7 +252,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modulesToInstallByInstance() {
|
||||
void modulesToInstallByInstance() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(new CustomIntegerModule())
|
||||
.build();
|
||||
@@ -261,7 +261,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wellKnownModules() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
void wellKnownModules() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||
|
||||
Long timestamp = 1322903730000L;
|
||||
@@ -280,7 +280,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
public void customizeWellKnownModulesWithModule()
|
||||
void customizeWellKnownModulesWithModule()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
@@ -293,7 +293,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
@Test // SPR-12634
|
||||
@SuppressWarnings("unchecked")
|
||||
public void customizeWellKnownModulesWithModuleClass()
|
||||
void customizeWellKnownModulesWithModuleClass()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
@@ -305,7 +305,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
public void customizeWellKnownModulesWithSerializer()
|
||||
void customizeWellKnownModulesWithSerializer()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
@@ -316,7 +316,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // gh-22576
|
||||
public void overrideWellKnownModuleWithModule() throws IOException {
|
||||
void overrideWellKnownModuleWithModule() throws IOException {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addDeserializer(OffsetDateTime.class, new OffsetDateTimeDeserializer());
|
||||
@@ -328,7 +328,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // gh-22740
|
||||
public void registerMultipleModulesWithNullTypeId() {
|
||||
void registerMultipleModulesWithNullTypeId() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
||||
SimpleModule fooModule = new SimpleModule();
|
||||
fooModule.addSerializer(new FooSerializer());
|
||||
@@ -355,7 +355,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyNamingStrategy() {
|
||||
void propertyNamingStrategy() {
|
||||
PropertyNamingStrategy strategy = new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().propertyNamingStrategy(strategy).build();
|
||||
assertThat(objectMapper.getSerializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
|
||||
@@ -363,7 +363,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializerByType() {
|
||||
void serializerByType() {
|
||||
JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modules(new ArrayList<>()) // Disable well-known modules detection
|
||||
@@ -375,7 +375,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializerByType() throws JsonMappingException {
|
||||
void deserializerByType() throws JsonMappingException {
|
||||
JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modules(new ArrayList<>()) // Disable well-known modules detection
|
||||
@@ -387,7 +387,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mixIn() {
|
||||
void mixIn() {
|
||||
Class<?> target = String.class;
|
||||
Class<?> mixInSource = Object.class;
|
||||
|
||||
@@ -400,7 +400,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mixIns() {
|
||||
void mixIns() {
|
||||
Class<?> target = String.class;
|
||||
Class<?> mixInSource = Object.class;
|
||||
Map<Class<?>, Class<?>> mixIns = new HashMap<>();
|
||||
@@ -415,7 +415,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filters() throws JsonProcessingException {
|
||||
void filters() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.filters(new SimpleFilterProvider().setFailOnUnknownId(false)).build();
|
||||
JacksonFilteredBean bean = new JacksonFilteredBean("value1", "value2");
|
||||
@@ -433,7 +433,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // gh-23017
|
||||
public void postConfigurer() {
|
||||
void postConfigurer() {
|
||||
|
||||
JacksonAnnotationIntrospector introspector1 = new JacksonAnnotationIntrospector();
|
||||
JacksonAnnotationIntrospector introspector2 = new JacksonAnnotationIntrospector();
|
||||
@@ -447,7 +447,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void completeSetup() throws JsonMappingException {
|
||||
void completeSetup() throws JsonMappingException {
|
||||
NopAnnotationIntrospector introspector = NopAnnotationIntrospector.instance;
|
||||
|
||||
Map<Class<?>, JsonDeserializer<?>> deserializerMap = new HashMap<>();
|
||||
@@ -511,14 +511,14 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlMapper() {
|
||||
void xmlMapper() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.getClass()).isEqualTo(XmlMapper.class);
|
||||
}
|
||||
|
||||
@Test // gh-22428
|
||||
public void xmlMapperAndCustomFactory() {
|
||||
void xmlMapperAndCustomFactory() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().factory(new MyXmlFactory()).build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.getClass()).isEqualTo(XmlMapper.class);
|
||||
@@ -526,7 +526,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createXmlMapper() {
|
||||
void createXmlMapper() {
|
||||
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json().indentOutput(true);
|
||||
ObjectMapper jsonObjectMapper = builder.build();
|
||||
ObjectMapper xmlObjectMapper = builder.createXmlMapper(true).build();
|
||||
@@ -536,7 +536,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13975
|
||||
public void defaultUseWrapper() throws JsonProcessingException {
|
||||
void defaultUseWrapper() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().defaultUseWrapper(false).build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.getClass()).isEqualTo(XmlMapper.class);
|
||||
@@ -546,21 +546,21 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
@Test // SPR-14435
|
||||
public void smile() {
|
||||
void smile() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.smile().build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.getFactory().getClass()).isEqualTo(SmileFactory.class);
|
||||
}
|
||||
|
||||
@Test // SPR-14435
|
||||
public void cbor() {
|
||||
void cbor() {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.cbor().build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.getFactory().getClass()).isEqualTo(CBORFactory.class);
|
||||
}
|
||||
|
||||
@Test // SPR-14435
|
||||
public void factory() {
|
||||
void factory() {
|
||||
ObjectMapper objectMapper = new Jackson2ObjectMapperBuilder().factory(new SmileFactory()).build();
|
||||
assertThat(objectMapper).isNotNull();
|
||||
assertThat(objectMapper.getFactory().getClass()).isEqualTo(SmileFactory.class);
|
||||
@@ -568,7 +568,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void visibility() throws JsonProcessingException {
|
||||
void visibility() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.visibility(PropertyAccessor.GETTER, Visibility.NONE)
|
||||
.visibility(PropertyAccessor.FIELD, Visibility.ANY)
|
||||
@@ -580,7 +580,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
assertThat(json).doesNotContain("property3");
|
||||
}
|
||||
|
||||
public static class CustomIntegerModule extends Module {
|
||||
static class CustomIntegerModule extends Module {
|
||||
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
@@ -601,7 +601,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
|
||||
public static class CustomIntegerSerializer extends JsonSerializer<Integer> {
|
||||
static class CustomIntegerSerializer extends JsonSerializer<Integer> {
|
||||
|
||||
@Override
|
||||
public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers)
|
||||
@@ -615,7 +615,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
|
||||
|
||||
@JsonFilter("myJacksonFilter")
|
||||
public static class JacksonFilteredBean {
|
||||
static class JacksonFilteredBean {
|
||||
|
||||
public JacksonFilteredBean() {
|
||||
}
|
||||
@@ -646,7 +646,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
|
||||
|
||||
public static class ListContainer<T> {
|
||||
static class ListContainer<T> {
|
||||
|
||||
private List<T> list;
|
||||
|
||||
@@ -666,7 +666,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class JacksonVisibilityBean {
|
||||
static class JacksonVisibilityBean {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String property1;
|
||||
|
||||
Reference in New Issue
Block a user