Skip to content

Commit 22f527a

Browse files
minwoo1999philwebb
authored andcommitted
Add test for nullSafeValue with mapper transformation
See gh-43441
1 parent 51c9925 commit 22f527a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.math.BigDecimal;
2121
import java.math.BigInteger;
22+
import java.util.function.Function;
2223

2324
import com.fasterxml.jackson.core.JsonParser;
2425
import com.fasterxml.jackson.core.ObjectCodec;
@@ -144,6 +145,18 @@ void nullSafeValueWhenClassIsBigIntegerShouldReturnBigInteger() {
144145
assertThat(value).isEqualTo(BigInteger.TEN);
145146
}
146147

148+
@Test
149+
void nullSafeValueWithMapperShouldTransformValue() {
150+
JsonNode node = mock(JsonNode.class);
151+
given(node.textValue()).willReturn("2023-12-01");
152+
153+
java.time.LocalDate result = this.testDeserializer.testNullSafeValue(
154+
node, String.class, java.time.LocalDate::parse
155+
);
156+
157+
assertThat(result).isEqualTo(java.time.LocalDate.of(2023, 12, 1));
158+
}
159+
147160
@Test
148161
void nullSafeValueWhenClassIsUnknownShouldThrowException() {
149162
assertThatIllegalArgumentException()
@@ -189,6 +202,11 @@ protected T deserializeObject(JsonParser jsonParser, DeserializationContext cont
189202
return null;
190203
}
191204

205+
<D, R> R testNullSafeValue(JsonNode jsonNode, Class<D> type, Function<D, R> mapper) {
206+
return nullSafeValue(jsonNode, type, mapper);
207+
}
208+
209+
192210
<D> D testNullSafeValue(JsonNode jsonNode, Class<D> type) {
193211
return nullSafeValue(jsonNode, type);
194212
}

0 commit comments

Comments
 (0)