2
2
3
3
import java .math .BigInteger ;
4
4
import java .time .Duration ;
5
- import java .time .LocalDateTime ;
6
5
import java .time .temporal .TemporalAmount ;
7
6
import java .util .Map ;
8
7
9
8
import com .fasterxml .jackson .annotation .JsonFormat ;
10
- import com .fasterxml .jackson .annotation .OptBoolean ;
11
9
import com .fasterxml .jackson .core .type .TypeReference ;
12
10
import org .junit .Test ;
13
11
21
19
import com .fasterxml .jackson .databind .JsonMappingException ;
22
20
import com .fasterxml .jackson .databind .ObjectMapper ;
23
21
import com .fasterxml .jackson .databind .ObjectReader ;
22
+ import com .fasterxml .jackson .databind .exc .InvalidFormatException ;
24
23
import com .fasterxml .jackson .databind .exc .MismatchedInputException ;
25
24
import com .fasterxml .jackson .datatype .jsr310 .MockObjectConfiguration ;
26
25
import com .fasterxml .jackson .datatype .jsr310 .ModuleTestBase ;
@@ -433,7 +432,7 @@ public void testStrictDeserializeFromEmptyString() throws Exception {
433
432
}
434
433
435
434
@ Test
436
- public void shouldDeserializeInHours_whenValueIsString () throws Exception {
435
+ public void shouldDeserializeInHours_whenUnitAsPattern_andValueIsString () throws Exception {
437
436
ObjectMapper mapper = newMapper ();
438
437
ObjectReader reader = mapper .readerFor (MAP_TYPE_REF );
439
438
@@ -442,8 +441,18 @@ public void shouldDeserializeInHours_whenValueIsString() throws Exception {
442
441
assertEquals (Duration .ofHours (25 ), wrapper .value );
443
442
}
444
443
444
+ @ Test (expected = InvalidFormatException .class )
445
+ public void shouldHandleException_whenUsingUnitAsPattern_andValueIsString () throws Exception {
446
+ ObjectMapper mapper = newMapper ();
447
+ ObjectReader reader = mapper .readerFor (MAP_TYPE_REF );
448
+
449
+ Wrapper wrapper = reader .readValue ("{\" value\" :\" FAIL\" }" , Wrapper .class );
450
+
451
+ assertEquals (Duration .ofHours (25 ), wrapper .value );
452
+ }
453
+
445
454
@ Test
446
- public void shouldDeserializeInHours_whenValueIsInteger () throws Exception {
455
+ public void shouldDeserializeInHours_whenUnitAsPattern_andValueIsInteger () throws Exception {
447
456
ObjectMapper mapper = newMapper ();
448
457
ObjectReader reader = mapper .readerFor (MAP_TYPE_REF );
449
458
@@ -453,7 +462,7 @@ public void shouldDeserializeInHours_whenValueIsInteger() throws Exception {
453
462
}
454
463
455
464
@ Test
456
- public void shouldDeserializeInHours_whenValueIsFloat () throws Exception {
465
+ public void shouldDeserializeInHours_whenUnitAsPattern_andValueIsFloat () throws Exception {
457
466
ObjectMapper mapper = newMapper ();
458
467
ObjectReader reader = mapper .readerFor (MAP_TYPE_REF );
459
468
0 commit comments