Skip to content

Commit 4a4b332

Browse files
committed
Refine Jackson2ObjectMapperBuilder#configureFeature exception handling
This commit changes the FatalBeanException previously thrown for an IllegalArgumentException which seems more suitable for that use case. Closes gh-29860
1 parent 33f1c9b commit 4a4b332

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -57,7 +57,6 @@
5757
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
5858

5959
import org.springframework.beans.BeanUtils;
60-
import org.springframework.beans.FatalBeanException;
6160
import org.springframework.context.ApplicationContext;
6261
import org.springframework.core.KotlinDetector;
6362
import org.springframework.lang.Nullable;
@@ -837,7 +836,7 @@ else if (feature instanceof MapperFeature) {
837836
objectMapper.configure((MapperFeature) feature, enabled);
838837
}
839838
else {
840-
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
839+
throw new IllegalArgumentException("Unknown feature class: " + feature.getClass().getName());
841840
}
842841
}
843842

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -83,11 +83,9 @@
8383
import org.joda.time.DateTimeZone;
8484
import org.junit.jupiter.api.Test;
8585

86-
import org.springframework.beans.FatalBeanException;
8786
import org.springframework.util.StringUtils;
8887

8988
import static org.assertj.core.api.Assertions.assertThat;
90-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
9189
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
9290

9391
/**
@@ -106,7 +104,7 @@ class Jackson2ObjectMapperBuilderTests {
106104

107105
@Test
108106
void unknownFeature() {
109-
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
107+
assertThatIllegalArgumentException().isThrownBy(() ->
110108
Jackson2ObjectMapperBuilder.json().featuresToEnable(Boolean.TRUE).build());
111109
}
112110

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -62,10 +62,8 @@
6262
import org.joda.time.DateTimeZone;
6363
import org.junit.jupiter.api.Test;
6464

65-
import org.springframework.beans.FatalBeanException;
66-
6765
import static org.assertj.core.api.Assertions.assertThat;
68-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
66+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
6967

7068
/**
7169
* Test cases for {@link Jackson2ObjectMapperFactoryBean}.
@@ -88,8 +86,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
8886
@Test
8987
public void unknownFeature() {
9088
this.factory.setFeaturesToEnable(Boolean.TRUE);
91-
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(
92-
this.factory::afterPropertiesSet);
89+
assertThatIllegalArgumentException().isThrownBy(this.factory::afterPropertiesSet);
9390
}
9491

9592
@Test

0 commit comments

Comments
 (0)