File tree Expand file tree Collapse file tree
libraries-jackson/jackson/src/test/java/com/ossez/jackson/optionalwithjackson Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .ossez .jackson .optionalwithjackson ;
22
33import com .fasterxml .jackson .core .JsonProcessingException ;
4+ import com .fasterxml .jackson .databind .JsonMappingException ;
45import com .fasterxml .jackson .databind .ObjectMapper ;
56import com .fasterxml .jackson .datatype .jdk8 .Jdk8Module ;
7+
68import static io .restassured .path .json .JsonPath .from ;
9+
710import java .io .IOException ;
811import java .util .Optional ;
12+
913import static org .assertj .core .api .Assertions .assertThat ;
14+
1015import org .junit .Test ;
1116
1217public class OptionalTypeUnitTest {
1318
1419 ObjectMapper mapper = new ObjectMapper ().registerModule (new Jdk8Module ());
1520
16- @ Test
1721 public void givenPresentOptional_whenSerializing_thenValueInJson () throws JsonProcessingException {
1822
1923 String subTitle = "The Parish Boy's Progress" ;
@@ -26,6 +30,12 @@ public void givenPresentOptional_whenSerializing_thenValueInJson() throws JsonPr
2630 assertThat (from (result ).getString ("subTitle" )).isEqualTo (subTitle );
2731 }
2832
33+ @ Test
34+ public void givenFieldWithValue_whenDeserializing_thenThrowExceptio () throws JsonProcessingException {
35+ String bookJson = "{ \" title\" : \" Oliver Twist\" , \" subTitle\" : \" foo\" }" ;
36+ Book result = mapper .readValue (bookJson , Book .class );
37+ }
38+
2939 @ Test
3040 public void givenEmptyOptional_whenSerializing_thenNullValue () throws JsonProcessingException {
3141
You can’t perform that action at this time.
0 commit comments