|
1 | 1 | package com.fasterxml.jackson.databind.deser.jdk;
|
2 | 2 |
|
3 |
| -import static org.junit.jupiter.api.Assertions.assertThrows; |
4 |
| -import com.fasterxml.jackson.core.JsonProcessingException; |
5 |
| -import com.fasterxml.jackson.databind.BaseMapTest; |
6 |
| -import com.fasterxml.jackson.databind.DeserializationFeature; |
7 |
| -import com.fasterxml.jackson.databind.ObjectMapper; |
8 |
| -import com.fasterxml.jackson.databind.ObjectReader; |
9 | 3 | import java.util.Locale;
|
10 | 4 |
|
| 5 | +import com.fasterxml.jackson.databind.*; |
| 6 | + |
11 | 7 | // [databind#4009] Locale "" is deserialised as NULL if ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is true
|
12 | 8 | public class LocaleDeser4009Test extends BaseMapTest
|
13 | 9 | {
|
14 |
| - |
15 |
| - static class MyPojo { |
16 |
| - public String field; |
17 |
| - } |
18 |
| - final ObjectMapper mapper = newJsonMapper(); |
19 |
| - |
20 |
| - final ObjectReader DISABLED_READER = mapper.reader() |
21 |
| - .without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); |
22 |
| - |
23 |
| - final ObjectReader ENABLED_READER = mapper.reader() |
24 |
| - .with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); |
25 |
| - |
26 |
| - public void testPOJOWithFeatureDisabled() |
27 |
| - { |
28 |
| - assertThrows(JsonProcessingException.class, () -> { |
29 |
| - DISABLED_READER.readValue("\"\"", MyPojo.class); |
30 |
| - }); |
31 |
| - } |
32 |
| - |
33 |
| - public void testPOJOWithFeatureEnabled() throws Exception |
34 |
| - { |
35 |
| - assertNull(ENABLED_READER.readValue("\"\"", MyPojo.class)); |
36 |
| - } |
| 10 | + private final ObjectMapper MAPPER = newJsonMapper(); |
37 | 11 |
|
38 | 12 | public void testLocaleWithFeatureDisabled() throws Exception
|
39 | 13 | {
|
40 |
| - assertEquals(Locale.ROOT, DISABLED_READER.readValue("\"\"", Locale.class)); |
| 14 | + assertEquals(Locale.ROOT, |
| 15 | + MAPPER.readerFor(Locale.class) |
| 16 | + .without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) |
| 17 | + .readValue("\"\"")); |
41 | 18 | }
|
42 | 19 |
|
43 | 20 | public void testLocaleWithFeatureEnabled() throws Exception
|
44 | 21 | {
|
45 |
| - assertNull(ENABLED_READER.readValue("\"\"", Locale.class)); |
| 22 | + assertNull(MAPPER.readerFor(Locale.class) |
| 23 | + .with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) |
| 24 | + .readValue("\"\"")); |
46 | 25 | }
|
47 | 26 | }
|
0 commit comments