From 22f527af6aeb02fdc244cdc931de4dc8147760db Mon Sep 17 00:00:00 2001 From: KIM MIN WOO <79193811+minwoo1999@users.noreply.github.com> Date: Sun, 8 Dec 2024 16:51:41 +0900 Subject: [PATCH 1/2] Add test for nullSafeValue with mapper transformation See gh-43441 --- .../jackson/JsonObjectDeserializerTests.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java index 8461ce6ae8..57f505f7cf 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java @@ -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; } + R testNullSafeValue(JsonNode jsonNode, Class type, Function mapper) { + return nullSafeValue(jsonNode, type, mapper); + } + + D testNullSafeValue(JsonNode jsonNode, Class type) { return nullSafeValue(jsonNode, type); } From d5d7152e5dcad80722e270fa998360f64dfabc62 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 11 Dec 2024 15:13:48 -0800 Subject: [PATCH 2/2] Polish 'Add test for nullSafeValue with mapper transformation' See gh-43441 --- .../boot/jackson/JsonObjectDeserializerTests.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java index 57f505f7cf..c0c23acb47 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jackson/JsonObjectDeserializerTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.boot.jackson; import java.io.InputStream; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.LocalDate; import java.util.function.Function; import com.fasterxml.jackson.core.JsonParser; @@ -149,12 +150,8 @@ class JsonObjectDeserializerTests { 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)); + LocalDate result = this.testDeserializer.testNullSafeValue(node, String.class, LocalDate::parse); + assertThat(result).isEqualTo(LocalDate.of(2023, 12, 1)); } @Test @@ -206,7 +203,6 @@ class JsonObjectDeserializerTests { return nullSafeValue(jsonNode, type, mapper); } - D testNullSafeValue(JsonNode jsonNode, Class type) { return nullSafeValue(jsonNode, type); }