From b498a8f105974a8d9cb7e65faf08679ddd146fe4 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Mon, 6 May 2024 09:29:53 -0400 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../optionalwithjackson/OptionalTypeUnitTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries-jackson/jackson/src/test/java/com/ossez/jackson/optionalwithjackson/OptionalTypeUnitTest.java b/libraries-jackson/jackson/src/test/java/com/ossez/jackson/optionalwithjackson/OptionalTypeUnitTest.java index 89611a74d0..6cd6590fd8 100644 --- a/libraries-jackson/jackson/src/test/java/com/ossez/jackson/optionalwithjackson/OptionalTypeUnitTest.java +++ b/libraries-jackson/jackson/src/test/java/com/ossez/jackson/optionalwithjackson/OptionalTypeUnitTest.java @@ -1,19 +1,23 @@ package com.ossez.jackson.optionalwithjackson; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; + import static io.restassured.path.json.JsonPath.from; + import java.io.IOException; import java.util.Optional; + import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; public class OptionalTypeUnitTest { ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module()); - @Test public void givenPresentOptional_whenSerializing_thenValueInJson() throws JsonProcessingException { String subTitle = "The Parish Boy's Progress"; @@ -26,6 +30,12 @@ public class OptionalTypeUnitTest { assertThat(from(result).getString("subTitle")).isEqualTo(subTitle); } + @Test + public void givenFieldWithValue_whenDeserializing_thenThrowExceptio() throws JsonProcessingException { + String bookJson = "{ \"title\": \"Oliver Twist\", \"subTitle\": \"foo\" }"; + Book result = mapper.readValue(bookJson, Book.class); + } + @Test public void givenEmptyOptional_whenSerializing_thenNullValue() throws JsonProcessingException { -- 2.46.2