Merge pull request #43441 from minwoo1999

* pr/43441:
  Polish 'Add test for nullSafeValue with mapper transformation'
  Add test for nullSafeValue with mapper transformation

Closes gh-43441
This commit is contained in:
Phillip Webb 2024-12-11 15:14:25 -08:00
commit 15f5811f3d
1 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,8 @@ package org.springframework.boot.jackson;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.time.LocalDate;
import java.util.function.Function;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.core.ObjectCodec;
@ -144,6 +146,14 @@ class JsonObjectDeserializerTests {
assertThat(value).isEqualTo(BigInteger.TEN); assertThat(value).isEqualTo(BigInteger.TEN);
} }
@Test
void nullSafeValueWithMapperShouldTransformValue() {
JsonNode node = mock(JsonNode.class);
given(node.textValue()).willReturn("2023-12-01");
LocalDate result = this.testDeserializer.testNullSafeValue(node, String.class, LocalDate::parse);
assertThat(result).isEqualTo(LocalDate.of(2023, 12, 1));
}
@Test @Test
void nullSafeValueWhenClassIsUnknownShouldThrowException() { void nullSafeValueWhenClassIsUnknownShouldThrowException() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
@ -189,6 +199,10 @@ class JsonObjectDeserializerTests {
return null; 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) { <D> D testNullSafeValue(JsonNode jsonNode, Class<D> type) {
return nullSafeValue(jsonNode, type); return nullSafeValue(jsonNode, type);
} }