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)
| 739 | * @throws UncheckedIOException if an I/O exception is encountered |
| 740 | */ |
| 741 | private void expect(JsonType type) { |
| 742 | if (peek() != type) { |
| 743 | throw new JsonException( |
| 744 | "Expected to read a " + type + " but instead have: " + peek() + ". " + input); |
| 745 | } |
| 746 | |
| 747 | // The pending token is about to be consumed, so the memoized type is no longer valid. |
| 748 | peekedType = null; |
| 749 | |
| 750 | // Special map handling. Woo! |
| 751 | byte top = topContainer(); |
| 752 | |
| 753 | if (type == JsonType.NAME) { |
| 754 | if (top == MAP_NAME) { |
| 755 | containerState[containerDepth - 1] = MAP_VALUE; |
| 756 | return; |
| 757 | } else if (top != NONE) { |
| 758 | throw new JsonException("Unexpected attempt to read name. " + input); |
| 759 | } |
| 760 | |
| 761 | return; // End of Name handling |
| 762 | } |
| 763 | |
| 764 | // Handle the case where we're reading a value. |
| 765 | if (type == JsonType.END_COLLECTION || type == JsonType.END_MAP) { |
| 766 | // Closing the container - don't treat as a new element in it. |
| 767 | return; |
| 768 | } |
| 769 | if (top == MAP_VALUE) { |
| 770 | containerState[containerDepth - 1] = MAP_NAME; |
| 771 | markElementRead(); |
| 772 | } else if (top == COLLECTION) { |
| 773 | markElementRead(); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | private byte topContainer() { |
| 778 | return containerDepth == 0 ? NONE : containerState[containerDepth - 1]; |
no test coverage detected