|
12 | 12 | import com.fasterxml.jackson.databind.ObjectMapper;
|
13 | 13 | import com.fasterxml.jackson.databind.cfg.CoercionAction;
|
14 | 14 | import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
|
| 15 | +import org.junit.Assert; |
15 | 16 |
|
16 | 17 | // [databind#3418]: Coercion from empty String to Collection<String>, with
|
17 | 18 | // `DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY`
|
@@ -113,4 +114,64 @@ public void testCoercedBlankToListWrapper() throws Exception {
|
113 | 114 | assertEquals(Collections.emptyList(),
|
114 | 115 | COERCION_MAPPER.readValue("\" \"", new TypeReference<List<StringWrapper>>() {}));
|
115 | 116 | }
|
| 117 | + |
| 118 | + public void testEmptyToArray() throws Exception { |
| 119 | + // NO coercion + empty string input + StringCollectionDeserializer |
| 120 | + Assert.assertArrayEquals(new String[]{""}, |
| 121 | + NORMAL_MAPPER.readValue("\"\"", new TypeReference<String[]>() {})); |
| 122 | + } |
| 123 | + |
| 124 | + public void testEmptyToArrayWrapper() throws Exception { |
| 125 | + // NO coercion + empty string input + normal CollectionDeserializer |
| 126 | + Assert.assertArrayEquals(new StringWrapper[]{new StringWrapper("")}, |
| 127 | + NORMAL_MAPPER.readValue("\"\"", new TypeReference<StringWrapper[]>() {})); |
| 128 | + } |
| 129 | + |
| 130 | + public void testCoercedEmptyToArray() throws Exception { |
| 131 | + // YES coercion + empty string input + StringCollectionDeserializer |
| 132 | + Assert.assertArrayEquals(new String[0], COERCION_MAPPER.readValue("\"\"", |
| 133 | + new TypeReference<String[]>() {})); |
| 134 | + } |
| 135 | + |
| 136 | + public void testCoercedEmptyToArrayWrapper() throws Exception { |
| 137 | + // YES coercion + empty string input + normal CollectionDeserializer |
| 138 | + Assert.assertArrayEquals(new StringWrapper[0], |
| 139 | + COERCION_MAPPER.readValue("\"\"", new TypeReference<StringWrapper[]>() {})); |
| 140 | + } |
| 141 | + |
| 142 | + public void testCoercedListToArray() throws Exception { |
| 143 | + // YES coercion + empty LIST input + StringCollectionDeserializer |
| 144 | + Assert.assertArrayEquals(new String[0], |
| 145 | + COERCION_MAPPER.readValue("[]", new TypeReference<String[]>() {})); |
| 146 | + } |
| 147 | + |
| 148 | + public void testCoercedListToArrayWrapper() throws Exception { |
| 149 | + // YES coercion + empty LIST input + normal CollectionDeserializer |
| 150 | + Assert.assertArrayEquals(new StringWrapper[0], |
| 151 | + COERCION_MAPPER.readValue("[]", new TypeReference<StringWrapper[]>() {})); |
| 152 | + } |
| 153 | + |
| 154 | + public void testBlankToArray() throws Exception { |
| 155 | + // NO coercion + empty string input + StringCollectionDeserializer |
| 156 | + Assert.assertArrayEquals(new String[]{" "}, |
| 157 | + NORMAL_MAPPER.readValue("\" \"", new TypeReference<String[]>() {})); |
| 158 | + } |
| 159 | + |
| 160 | + public void testBlankToArrayWrapper() throws Exception { |
| 161 | + // NO coercion + empty string input + normal CollectionDeserializer |
| 162 | + Assert.assertArrayEquals(new StringWrapper[]{new StringWrapper(" ")}, |
| 163 | + NORMAL_MAPPER.readValue("\" \"", new TypeReference<StringWrapper[]>() {})); |
| 164 | + } |
| 165 | + |
| 166 | + public void testCoercedBlankToArray() throws Exception { |
| 167 | + // YES coercion + empty string input + StringCollectionDeserializer |
| 168 | + Assert.assertArrayEquals(new String[0], |
| 169 | + COERCION_MAPPER.readValue("\" \"", new TypeReference<String[]>() {})); |
| 170 | + } |
| 171 | + |
| 172 | + public void testCoercedBlankToArrayWrapper() throws Exception { |
| 173 | + // YES coercion + empty string input + normal CollectionDeserializer |
| 174 | + Assert.assertArrayEquals(new StringWrapper[0], |
| 175 | + COERCION_MAPPER.readValue("\" \"", new TypeReference<StringWrapper[]>() {})); |
| 176 | + } |
116 | 177 | }
|
0 commit comments