Add test for nullSafeValue with mapper transformation
See gh-43441
This commit is contained in:
parent
51c992593f
commit
22f527af6a
|
@ -19,6 +19,7 @@ package org.springframework.boot.jackson;
|
|||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
|
@ -144,6 +145,18 @@ class JsonObjectDeserializerTests {
|
|||
assertThat(value).isEqualTo(BigInteger.TEN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullSafeValueWithMapperShouldTransformValue() {
|
||||
JsonNode node = mock(JsonNode.class);
|
||||
given(node.textValue()).willReturn("2023-12-01");
|
||||
|
||||
java.time.LocalDate result = this.testDeserializer.testNullSafeValue(
|
||||
node, String.class, java.time.LocalDate::parse
|
||||
);
|
||||
|
||||
assertThat(result).isEqualTo(java.time.LocalDate.of(2023, 12, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullSafeValueWhenClassIsUnknownShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
|
@ -189,6 +202,11 @@ class JsonObjectDeserializerTests {
|
|||
return null;
|
||||
}
|
||||
|
||||
<D, R> R testNullSafeValue(JsonNode jsonNode, Class<D> type, Function<D, R> mapper) {
|
||||
return nullSafeValue(jsonNode, type, mapper);
|
||||
}
|
||||
|
||||
|
||||
<D> D testNullSafeValue(JsonNode jsonNode, Class<D> type) {
|
||||
return nullSafeValue(jsonNode, type);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue