Refine search
/** * Convenience method, equivalent to: *<pre> * TokenBuffer b = new TokenBuffer(p); * b.copyCurrentStructure(p); * return b; *</pre> * * @since 2.9 */ public static TokenBuffer asCopyOfValue(JsonParser p) throws IOException { TokenBuffer b = new TokenBuffer(p); b.copyCurrentStructure(p); return b; }
/** * Helper method that will append contents of given buffer into this * buffer. * Not particularly optimized; can be made faster if there is need. * * @return This buffer */ @SuppressWarnings("resource") public TokenBuffer append(TokenBuffer other) throws IOException { // Important? If source has native ids, need to store if (!_hasNativeTypeIds) { _hasNativeTypeIds = other.canWriteTypeId(); } if (!_hasNativeObjectIds) { _hasNativeObjectIds = other.canWriteObjectId(); } _mayHaveNativeIds = _hasNativeTypeIds | _hasNativeObjectIds; JsonParser p = other.asParser(); while (p.nextToken() != null) { copyCurrentStructure(p); } return this; }
t = p.nextToken(); } else if (/*t == JsonToken.START_ARRAY ||*/ t != JsonToken.FIELD_NAME) { for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String name = p.getCurrentName(); p.nextToken(); // to point to the value if (name.equals(_typePropertyName)) { // gotcha! return _deserializeTypedForId(p, ctxt, tb); tb = new TokenBuffer(p, ctxt); tb.copyCurrentStructure(p);
@SuppressWarnings("resource") protected final Object _deserialize(JsonParser p, DeserializationContext ctxt, int index, String typeId) throws IOException { JsonParser p2 = _tokens[index].asParser(p); JsonToken t = p2.nextToken(); // 29-Sep-2015, tatu: As per [databind#942], nulls need special support if (t == JsonToken.VALUE_NULL) { return null; } TokenBuffer merged = new TokenBuffer(p, ctxt); merged.writeStartArray(); merged.writeString(typeId); merged.copyCurrentStructure(p2); merged.writeEndArray(); // needs to point to START_OBJECT (or whatever first token is) JsonParser mp = merged.asParser(p); mp.nextToken(); return _properties[index].getProperty().deserialize(mp, ctxt); }
/** * Helper method used by standard deserializer. * * @since 2.3 */ public TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.getCurrentTokenId() != JsonToken.FIELD_NAME.id()) { copyCurrentStructure(p); return this; } /* 28-Oct-2014, tatu: As per [databind#592], need to support a special case of starting from * FIELD_NAME, which is taken to mean that we are missing START_OBJECT, but need * to assume one did exist. */ JsonToken t; writeStartObject(); do { copyCurrentStructure(p); } while ((t = p.nextToken()) == JsonToken.FIELD_NAME); if (t != JsonToken.END_OBJECT) { ctxt.reportWrongTokenException(TokenBuffer.class, JsonToken.END_OBJECT, "Expected END_OBJECT after copying contents of a JsonParser into TokenBuffer, got "+t); // never gets here } writeEndObject(); return this; }
/** * Reads current value including objects and array as effiecient token buffer. * Use of Jackson's own mechanisms is important to preserve custom elements * such as special embedded objects in BSON or other data formats. * @return {@link TokenBuffer} * @throws IOException if error occured */ public final TokenBuffer nextTokenBuffer() throws IOException { TokenBuffer buffer = new TokenBuffer(parser); // if token is consumed, but undelying parser is still sitting on this token, we move forward requirePeek(); buffer.copyCurrentStructure(parser); // when we will return to reading from reader, state will be cleared and nextToken after clearPeek(); return buffer; }
@SuppressWarnings("resource") protected final void _deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object bean, int index, String typeId) throws IOException { /* Ok: time to mix type id, value; and we will actually use "wrapper-array" * style to ensure we can handle all kinds of JSON constructs. */ JsonParser p2 = _tokens[index].asParser(p); JsonToken t = p2.nextToken(); // 29-Sep-2015, tatu: As per [databind#942], nulls need special support if (t == JsonToken.VALUE_NULL) { _properties[index].getProperty().set(bean, null); return; } TokenBuffer merged = new TokenBuffer(p, ctxt); merged.writeStartArray(); merged.writeString(typeId); merged.copyCurrentStructure(p2); merged.writeEndArray(); // needs to point to START_OBJECT (or whatever first token is) JsonParser mp = merged.asParser(p); mp.nextToken(); _properties[index].getProperty().deserializeAndSet(mp, ctxt, bean); }
t = p.nextToken(); case START_ARRAY: writeStartArray(); while (p.nextToken() != JsonToken.END_ARRAY) { copyCurrentStructure(p); case START_OBJECT: writeStartObject(); while (p.nextToken() != JsonToken.END_OBJECT) { copyCurrentStructure(p);
TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.copyCurrentStructure(p); _tokens[index] = tokens; while (it.hasNext()) { } else { @SuppressWarnings("resource") TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.copyCurrentStructure(p); _tokens[index] = tokens; canDeserialize = (bean != null) && (_typeIds[index] != null);
t = p.nextToken(); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); p.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { tokens.copyCurrentStructure(p); } else {
for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); p.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { tokens.copyCurrentStructure(p);
private TokenBuffer createTokenBuffer(JsonParser jsonParser) throws IOException { TokenBuffer tokenBuffer = new TokenBuffer(mapper, true); tokenBuffer.copyCurrentStructure(jsonParser); return tokenBuffer; }
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); // to point to value t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT Object bean; try { p.nextToken(); // to skip name tokens.copyCurrentStructure(p); t = p.nextToken();
@Override public void copyCurrentStructure(JsonParser jp) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); // Let's handle field-name separately first if (t == JsonToken.FIELD_NAME) { writeFieldName(jp.getCurrentName()); t = jp.nextToken(); // fall-through to copy the associated value } switch (t) { case START_ARRAY: writeStartArray(); while (jp.nextToken() != JsonToken.END_ARRAY) { copyCurrentStructure(jp); } writeEndArray(); break; case START_OBJECT: writeStartObject(); while (jp.nextToken() != JsonToken.END_OBJECT) { copyCurrentStructure(jp); } writeEndObject(); break; default: // others are simple: copyCurrentEvent(jp); } }
/** * Convenience method, equivalent to: *<pre> * TokenBuffer b = new TokenBuffer(p); * b.copyCurrentStructure(p); * return b; *</pre> * * @since 2.9 */ public static TokenBuffer asCopyOfValue(JsonParser p) throws IOException { TokenBuffer b = new TokenBuffer(p); b.copyCurrentStructure(p); return b; }
return deserializeUsingPropertyBasedWithUnwrapped(p, ctxt); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); Object bean = _valueInstantiator.createUsingDefault(ctxt); for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case tokens.copyCurrentStructure(p);
@Override public void copyCurrentStructure(JsonParser jp) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); // Let's handle field-name separately first if (t == JsonToken.FIELD_NAME) { writeFieldName(jp.getCurrentName()); t = jp.nextToken(); // fall-through to copy the associated value } switch (t) { case START_ARRAY: writeStartArray(); while (jp.nextToken() != JsonToken.END_ARRAY) { copyCurrentStructure(jp); } writeEndArray(); break; case START_OBJECT: writeStartObject(); while (jp.nextToken() != JsonToken.END_OBJECT) { copyCurrentStructure(jp); } writeEndObject(); break; default: // others are simple: copyCurrentEvent(jp); } }
@Override public TokenBuffer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { TokenBuffer tb = new TokenBuffer(jp.getCodec()); // quite simple, given that TokenBuffer is a JsonGenerator: tb.copyCurrentStructure(jp); return tb; } }
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); Object builder = null; for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); // to point to value t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT try { builder = creator.build(ctxt, buffer); tokens.copyCurrentStructure(p);
/** * Helper method used by standard deserializer. * * @since 2.3 */ public TokenBuffer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (jp.getCurrentTokenId() != JsonToken.FIELD_NAME.id()) { copyCurrentStructure(jp); return this; } /* 28-Oct-2014, tatu: As per #592, need to support a special case of starting from * FIELD_NAME, which is taken to mean that we are missing START_OBJECT, but need * to assume one did exist. */ JsonToken t; writeStartObject(); do { copyCurrentStructure(jp); } while ((t = jp.nextToken()) == JsonToken.FIELD_NAME); if (t != JsonToken.END_OBJECT) { throw ctxt.mappingException("Expected END_OBJECT after copying contents of a JsonParser into TokenBuffer, got "+t); } writeEndObject(); return this; }