|
10 | 10 | import com.fasterxml.jackson.databind.MappingIterator;
|
11 | 11 | import com.fasterxml.jackson.databind.ObjectMapper;
|
12 | 12 | import com.fasterxml.jackson.databind.ObjectReader;
|
| 13 | +import com.fasterxml.jackson.databind.json.JsonMapper; |
13 | 14 |
|
14 | 15 | @SuppressWarnings("resource")
|
15 | 16 | public class ReadValuesTest extends BaseMapTest
|
@@ -307,7 +308,27 @@ public void testNonRootMapsWithObjectReader() throws Exception
|
307 | 308 | assertEquals(2, map.size());
|
308 | 309 | assertFalse(iterator.hasNext());
|
309 | 310 | }
|
310 |
| - |
| 311 | + |
| 312 | + public void testObjectReaderWithJsonParserFastDoubleParser() throws Exception |
| 313 | + { |
| 314 | + testObjectReaderWithFastDoubleParser(true); |
| 315 | + } |
| 316 | + |
| 317 | + public void testObjectReaderWithJsonReadFeatureFastDoubleParser() throws Exception |
| 318 | + { |
| 319 | + testObjectReaderWithFastDoubleParser(false); |
| 320 | + } |
| 321 | + |
| 322 | + public void testObjectReaderWithJsonParserFastFloatParser() throws Exception |
| 323 | + { |
| 324 | + testObjectReaderWithFastFloatParser(true); |
| 325 | + } |
| 326 | + |
| 327 | + public void testObjectReaderWithJsonReadFeatureFastFloatParser() throws Exception |
| 328 | + { |
| 329 | + testObjectReaderWithFastFloatParser(false); |
| 330 | + } |
| 331 | + |
311 | 332 | public void testNonRootArraysUsingParser() throws Exception
|
312 | 333 | {
|
313 | 334 | final String JSON = "[[1],[3]]";
|
@@ -342,4 +363,59 @@ public void testEmptyIterator() throws Exception
|
342 | 363 |
|
343 | 364 | empty.close();
|
344 | 365 | }
|
| 366 | + |
| 367 | + private void testObjectReaderWithFastDoubleParser(final boolean useParserFeature) throws Exception |
| 368 | + { |
| 369 | + final String JSON = "[{ \"val1\": 1.23456, \"val2\": 5 }, { \"val1\": 3.14, \"val2\": -6.5 }]"; |
| 370 | + final ObjectMapper mapper; |
| 371 | + if (useParserFeature) { |
| 372 | + JsonFactory factory = new JsonFactory(); |
| 373 | + factory.enable(JsonParser.Feature.USE_FAST_DOUBLE_PARSER); |
| 374 | + mapper = JsonMapper.builder(factory).build(); |
| 375 | + } else { |
| 376 | + mapper = JsonMapper.builder().enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER).build(); |
| 377 | + } |
| 378 | + |
| 379 | + final MappingIterator<Map<String, Double>> iterator = mapper.reader().forType(new TypeReference<Map<String, Double>>(){}).readValues(JSON); |
| 380 | + |
| 381 | + Map<String, Double> map; |
| 382 | + assertTrue(iterator.hasNext()); |
| 383 | + map = iterator.nextValue(); |
| 384 | + assertEquals(2, map.size()); |
| 385 | + assertEquals(Double.valueOf(1.23456), map.get("val1")); |
| 386 | + assertEquals(Double.valueOf(5), map.get("val2")); |
| 387 | + assertTrue(iterator.hasNext()); |
| 388 | + map = iterator.nextValue(); |
| 389 | + assertEquals(Double.valueOf(3.14), map.get("val1")); |
| 390 | + assertEquals(Double.valueOf(-6.5), map.get("val2")); |
| 391 | + assertEquals(2, map.size()); |
| 392 | + assertFalse(iterator.hasNext()); |
| 393 | + } |
| 394 | + |
| 395 | + private void testObjectReaderWithFastFloatParser(final boolean useParserFeature) throws Exception |
| 396 | + { |
| 397 | + final String JSON = "[{ \"val1\": 1.23456, \"val2\": 5 }, { \"val1\": 3.14, \"val2\": -6.5 }]"; |
| 398 | + final ObjectMapper mapper; |
| 399 | + if (useParserFeature) { |
| 400 | + JsonFactory factory = new JsonFactory(); |
| 401 | + factory.enable(JsonParser.Feature.USE_FAST_DOUBLE_PARSER); |
| 402 | + mapper = JsonMapper.builder(factory).build(); |
| 403 | + } else { |
| 404 | + mapper = JsonMapper.builder().enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER).build(); |
| 405 | + } |
| 406 | + final MappingIterator<Map<String, Float>> iterator = mapper.reader().forType(new TypeReference<Map<String, Float>>(){}).readValues(JSON); |
| 407 | + |
| 408 | + Map<String, Float> map; |
| 409 | + assertTrue(iterator.hasNext()); |
| 410 | + map = iterator.nextValue(); |
| 411 | + assertEquals(2, map.size()); |
| 412 | + assertEquals(Float.valueOf(1.23456f), map.get("val1")); |
| 413 | + assertEquals(Float.valueOf(5), map.get("val2")); |
| 414 | + assertTrue(iterator.hasNext()); |
| 415 | + map = iterator.nextValue(); |
| 416 | + assertEquals(Float.valueOf(3.14f), map.get("val1")); |
| 417 | + assertEquals(Float.valueOf(-6.5f), map.get("val2")); |
| 418 | + assertEquals(2, map.size()); |
| 419 | + assertFalse(iterator.hasNext()); |
| 420 | + } |
345 | 421 | }
|
0 commit comments