|
19 | 19 | import java.io.InputStream;
|
20 | 20 | import java.math.BigDecimal;
|
21 | 21 | import java.math.BigInteger;
|
| 22 | +import java.util.function.Function; |
22 | 23 |
|
23 | 24 | import com.fasterxml.jackson.core.JsonParser;
|
24 | 25 | import com.fasterxml.jackson.core.ObjectCodec;
|
@@ -144,6 +145,18 @@ void nullSafeValueWhenClassIsBigIntegerShouldReturnBigInteger() {
|
144 | 145 | assertThat(value).isEqualTo(BigInteger.TEN);
|
145 | 146 | }
|
146 | 147 |
|
| 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 | + |
147 | 160 | @Test
|
148 | 161 | void nullSafeValueWhenClassIsUnknownShouldThrowException() {
|
149 | 162 | assertThatIllegalArgumentException()
|
@@ -189,6 +202,11 @@ protected T deserializeObject(JsonParser jsonParser, DeserializationContext cont
|
189 | 202 | return null;
|
190 | 203 | }
|
191 | 204 |
|
| 205 | + <D, R> R testNullSafeValue(JsonNode jsonNode, Class<D> type, Function<D, R> mapper) { |
| 206 | + return nullSafeValue(jsonNode, type, mapper); |
| 207 | + } |
| 208 | + |
| 209 | + |
192 | 210 | <D> D testNullSafeValue(JsonNode jsonNode, Class<D> type) {
|
193 | 211 | return nullSafeValue(jsonNode, type);
|
194 | 212 | }
|
|
0 commit comments