Verify that the type of the pending JSON element matches the specified type. @param type expected JSON element type @throws JsonException if the pending element is not of the expected type @throws UncheckedIOException if an I/O exception is encountered
(JsonType type)
| 569 | * @throws UncheckedIOException if an I/O exception is encountered |
| 570 | */ |
| 571 | private void expect(JsonType type) { |
| 572 | if (peek() != type) { |
| 573 | throw new JsonException( |
| 574 | "Expected to read a " + type + " but instead have: " + peek() + ". " + input); |
| 575 | } |
| 576 | |
| 577 | // Special map handling. Woo! |
| 578 | Container top = stack.peekFirst(); |
| 579 | |
| 580 | if (type == JsonType.NAME) { |
| 581 | if (top == Container.MAP_NAME) { |
| 582 | stack.removeFirst(); |
| 583 | stack.addFirst(Container.MAP_VALUE); |
| 584 | return; |
| 585 | } else if (top != null) { |
| 586 | throw new JsonException("Unexpected attempt to read name. " + input); |
| 587 | } |
| 588 | |
| 589 | return; // End of Name handling |
| 590 | } |
| 591 | |
| 592 | // Handle the case where we're reading a value. |
| 593 | if (type == JsonType.END_COLLECTION || type == JsonType.END_MAP) { |
| 594 | // Closing the container - don't treat as a new element in it. |
| 595 | return; |
| 596 | } |
| 597 | if (top == Container.MAP_VALUE) { |
| 598 | stack.removeFirst(); |
| 599 | stack.addFirst(Container.MAP_NAME); |
| 600 | markElementRead(); |
| 601 | } else if (top == Container.COLLECTION) { |
| 602 | markElementRead(); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | private void markElementRead() { |
| 607 | if (!containerHasElement.isEmpty()) { |
no test coverage detected