|
| 1 | +package com.fasterxml.jackson.databind.deser.jdk; |
| 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 | +import java.util.Locale; |
| 10 | + |
| 11 | +// [databind#4009] Locale "" is deserialised as NULL if ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is true |
| 12 | +public class LocaleDeser4009Test extends BaseMapTest |
| 13 | +{ |
| 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 | + } |
| 37 | + |
| 38 | + public void testLocaleWithFeatureDisabled() throws Exception |
| 39 | + { |
| 40 | + assertEquals(Locale.ROOT, DISABLED_READER.readValue("\"\"", Locale.class)); |
| 41 | + } |
| 42 | + |
| 43 | + public void testLocaleWithFeatureEnabled() throws Exception |
| 44 | + { |
| 45 | + assertNull(ENABLED_READER.readValue("\"\"", Locale.class)); |
| 46 | + } |
| 47 | +} |
0 commit comments