protected final JsonToken _closeArrayScope() throws IOException { if (!_parsingContext.inArray()) { _reportMismatchedEndMarker(']', '}'); } JsonReadContext ctxt = _parsingContext.getParent(); _parsingContext = ctxt; int st; if (ctxt.inObject()) { st = MAJOR_OBJECT_FIELD_NEXT; } else if (ctxt.inArray()) { st = MAJOR_ARRAY_ELEMENT_NEXT; } else { st = MAJOR_ROOT; } _majorState = st; _majorStateAfterValue = st; return (_currToken = JsonToken.END_ARRAY); }
@Override public String nextTextValue() throws IOException { // two distinct cases; either got name and we know next type, or 'other' if (_currToken == JsonToken.FIELD_NAME) { // mostly copied from '_nextAfterName' _nameCopied = false; JsonToken t = _nextToken; _nextToken = null; _currToken = t; if (t == JsonToken.VALUE_STRING) { if (_tokenIncomplete) { _tokenIncomplete = false; return _finishAndReturnString(); } return _textBuffer.contentsAsString(); } if (t == JsonToken.START_ARRAY) { _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol); } else if (t == JsonToken.START_OBJECT) { _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol); } return null; } // !!! TODO: optimize this case as well return (nextToken() == JsonToken.VALUE_STRING) ? getText() : null; }
@Override public void overrideCurrentName(String name) { // Simple, but need to look for START_OBJECT/ARRAY's "off-by-one" thing: JsonReadContext ctxt = _parsingContext; if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) { ctxt = ctxt.getParent(); } /* 24-Sep-2013, tatu: Unfortunate, but since we did not expose exceptions, * need to wrap this here */ try { ctxt.setCurrentName(name); } catch (IOException e) { throw new IllegalStateException(e); } }
private final JsonToken _nextAfterName() { _nameCopied = false; // need to invalidate if it was copied JsonToken t = _nextToken; _nextToken = null; // Also: may need to start new context? if (t == JsonToken.START_ARRAY) { _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol); } else if (t == JsonToken.START_OBJECT) { _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol); } return (_currToken = t); }
/** * Method that can be called to get the name associated with * the current event. */ @Override public String getCurrentName() throws IOException { // [JACKSON-395]: start markers require information from parent if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) { JsonReadContext parent = _parsingContext.getParent(); if (parent != null) { return parent.getCurrentName(); } } return _parsingContext.getCurrentName(); }
private final void _closeArrayScope() throws JsonParseException { _updateLocation(); if (!_parsingContext.inArray()) { _reportMismatchedEndMarker(']', '}'); } _parsingContext = _parsingContext.clearAndGetParent(); }
switch (_currToken.id()) { String name = _parsingContext.getCurrentName(); int nameLen = name.length(); if (_nameCopyBuffer == null) { _nameCopyBuffer = _ioContext.allocNameCopyBuffer(nameLen); } else if (_nameCopyBuffer.length < nameLen) { _nameCopyBuffer = new char[nameLen]; if (_tokenIncomplete) { _tokenIncomplete = false; _finishString(); // only strings can be incomplete return _textBuffer.getTextBuffer(); return _currToken.asCharArray();
@Override public int getTextLength() throws IOException { if (_currToken != null) { // null only before/after document switch (_currToken.id()) { case ID_FIELD_NAME: return _parsingContext.getCurrentName().length(); case ID_STRING: // fall through case ID_NUMBER_INT: case ID_NUMBER_FLOAT: return _textBuffer.size(); default: return _currToken.asCharArray().length; } } return 0; }
_nextAfterName(); return false; _skipString(); int i = _skipWSOrEnd(); if (i < 0) { // end-of-input close(); if (_parsingContext.expectComma()) { if (i != INT_COMMA) { _reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); i = _skipWS(); if (!_parsingContext.inObject()) { _updateLocation(); _nextTokenNotInObject(i); while (true) { if (ptr == end) { // yes, match! _parsingContext.setCurrentName(str.getValue()); i = _skipColonFast(ptr+1); _isNextTokenNameYes(i);
protected final String _getText2(JsonToken t) { if (t == null) { return null; } switch (t.id()) { case ID_FIELD_NAME: return _parsingContext.getCurrentName(); case ID_STRING: // fall through case ID_NUMBER_INT: case ID_NUMBER_FLOAT: return _textBuffer.contentsAsString(); default: return t.asString(); } }
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment(); c = _verifyNoLeadingZeroes(); return _parseNumber2(outBuf, outPtr, false, intLen); return _parseFloat(outBuf, outPtr, c, false, intLen); _textBuffer.setCurrentLength(outPtr); if (_parsingContext.inRoot()) { _verifyRootSpace(c);
if (_parsingContext.inObject() && _currToken != JsonToken.FIELD_NAME) { if (!evt.is(Event.ID.Scalar)) { if (!_parsingContext.inObject()) { // sanity check is optional, but let's do it for now _reportMismatchedEndMarker('}', ']'); _parsingContext = _parsingContext.getParent(); return (_currToken = JsonToken.END_OBJECT); String name = scalar.getValue(); _currentFieldName = name; _parsingContext.setCurrentName(name); _currentAnchor = scalar.getAnchor(); return (_currToken = JsonToken.FIELD_NAME); MappingStartEvent map = (MappingStartEvent) evt; _currentAnchor = map.getAnchor(); _parsingContext = _parsingContext.createChildObjectContext(m.getLine(), m.getColumn()); return (_currToken = JsonToken.START_OBJECT); Mark m = evt.getStartMark(); _currentAnchor = ((NodeEvent)evt).getAnchor(); _parsingContext = _parsingContext.createChildArrayContext(m.getLine(), m.getColumn()); return (_currToken = JsonToken.START_ARRAY); if (!_parsingContext.inArray()) { // sanity check is optional, but let's do it for now _reportMismatchedEndMarker(']', '}'); _parsingContext = _parsingContext.getParent();
@Override // since 2.8 public int getText(Writer writer) throws IOException { JsonToken t = _currToken; if (t == JsonToken.VALUE_STRING) { if (_tokenIncomplete) { _tokenIncomplete = false; _finishString(); // only strings can be incomplete } return _textBuffer.contentsToWriter(writer); } if (t == JsonToken.FIELD_NAME) { String n = _parsingContext.getCurrentName(); writer.write(n); return n.length(); } if (t != null) { if (t.isNumeric()) { return _textBuffer.contentsToWriter(writer); } char[] ch = t.asCharArray(); writer.write(ch); return ch.length; } return 0; }
protected ParserBase(IOContext ctxt, int features) { super(features); _ioContext = ctxt; _textBuffer = ctxt.constructTextBuffer(); DupDetector dups = Feature.STRICT_DUPLICATE_DETECTION.enabledIn(features) ? DupDetector.rootDetector(this) : null; _parsingContext = JsonReadContext.createRootContext(dups); }
if (_inputPtr >= _inputEnd && !_loadMore()) { _textBuffer.setCurrentLength(outPtr); return resetInt(negative, intPartLength); return _parseFloat(outBuf, outPtr, c, negative, intPartLength); outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _textBuffer.setCurrentLength(outPtr); if (_parsingContext.inRoot()) { _verifyRootSpace(_inputBuffer[_inputPtr++] & 0xFF);
/** * Method called when an EOF is encountered between tokens. * If so, it may be a legitimate EOF, but only iff there * is no open non-root context. */ @Override protected void _handleEOF() throws JsonParseException { if (!_parsingContext.inRoot()) { _reportInvalidEOF(": expected close marker for "+_parsingContext.getTypeDesc()+" (from "+_parsingContext.getStartLocation(_ioContext.getSourceReference())+")"); } }
@Override public int getTextLength() throws IOException { if (_currToken == JsonToken.VALUE_STRING) { if (_tokenIncomplete) { _tokenIncomplete = false; _finishString(); // only strings can be incomplete } return _textBuffer.size(); } if (_currToken == JsonToken.FIELD_NAME) { return _parsingContext.getCurrentName().length(); } if (_currToken != null) { // null only before/after document if (_currToken.isNumeric()) { return _textBuffer.size(); } return _currToken.asCharArray().length; } return 0; }
outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; if (_inputPtr >= _inputEnd && !_loadMore()) { eof = true; break fract_loop; outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; reportUnexpectedNumberChar(c, "Decimal point not followed by a digit"); if (c == INT_e || c == INT_E) { // exponent? if (outPtr >= outBuf.length) { outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _loadMoreGuaranteed(); --_inputPtr; if (_parsingContext.inRoot()) { _verifyRootSpace(c);
String n = _parseName(i); _parsingContext.setCurrentName(n); final boolean match = n.equals(str.getValue()); _currToken = JsonToken.FIELD_NAME; i = _skipColon(); _updateLocation();
private void _closeScope(int i) throws JsonParseException { if (i == INT_RBRACKET) { if (!_parsingContext.inArray()) { _reportMismatchedEndMarker(i, '}'); } _parsingContext = _parsingContext.clearAndGetParent(); _currToken = JsonToken.END_ARRAY; } if (i == INT_RCURLY) { if (!_parsingContext.inObject()) { _reportMismatchedEndMarker(i, ']'); } _parsingContext = _parsingContext.clearAndGetParent(); _currToken = JsonToken.END_OBJECT; } }