|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.annotation.*;
|
4 | 4 | import com.fasterxml.jackson.core.type.TypeReference;
|
| 5 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
5 | 6 | import com.fasterxml.jackson.databind.ObjectMapper;
|
6 | 7 | import com.fasterxml.jackson.datatype.guava.pojo.AddOp;
|
7 | 8 | import com.fasterxml.jackson.datatype.guava.pojo.MathOp;
|
@@ -309,4 +310,44 @@ public void testPolymorphicValue() throws IOException {
|
309 | 310 | ImmutableMultimapWrapper output = MAPPER.readValue(json, ImmutableMultimapWrapper.class);
|
310 | 311 | assertEquals(input, output);
|
311 | 312 | }
|
| 313 | + |
| 314 | + public void testFromSingleValue() throws Exception |
| 315 | + { |
| 316 | + ObjectMapper mapper = mapperWithModule() |
| 317 | + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); |
| 318 | + SampleMultiMapTest sampleTest = mapper.readValue("{\"map\":{\"test\":\"value\"}}", |
| 319 | + new TypeReference<SampleMultiMapTest>() { }); |
| 320 | + |
| 321 | + assertEquals(1, sampleTest.map.get("test").size()); |
| 322 | + } |
| 323 | + |
| 324 | + public void testFromMultiValueWithSingleValueOptionEnabled() throws Exception |
| 325 | + { |
| 326 | + ObjectMapper mapper = mapperWithModule() |
| 327 | + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); |
| 328 | + |
| 329 | + SampleMultiMapTest sampleTest = mapper.readValue("{\"map\":{\"test\":\"val\",\"test1\":[\"val1\",\"val2\"]}}", |
| 330 | + new TypeReference<SampleMultiMapTest>() { }); |
| 331 | + |
| 332 | + assertEquals(1, sampleTest.map.get("test").size()); |
| 333 | + assertEquals(2, sampleTest.map.get("test1").size()); |
| 334 | + |
| 335 | + } |
| 336 | + |
| 337 | + public void testFromMultiValueWithNoSingleValueOptionEnabled() throws Exception |
| 338 | + { |
| 339 | + ObjectMapper mapper = mapperWithModule(); |
| 340 | + |
| 341 | + SampleMultiMapTest sampleTest = mapper.readValue("{\"map\":{\"test\":[\"val\"],\"test1\":[\"val1\",\"val2\"]}}", |
| 342 | + new TypeReference<SampleMultiMapTest>() { }); |
| 343 | + |
| 344 | + assertEquals(1, sampleTest.map.get("test").size()); |
| 345 | + assertEquals(2, sampleTest.map.get("test1").size()); |
| 346 | + |
| 347 | + } |
| 348 | + |
| 349 | + //Sample class for testing multimaps single value option |
| 350 | + static class SampleMultiMapTest { |
| 351 | + public HashMultimap<String, String> map; |
| 352 | + } |
312 | 353 | }
|
0 commit comments