Jackson Glossary: TokenBuffer
Package: org.codehaus.jackson.util
Jar: jackson-core
Role
TokenBuffer is a simple, efficient, in-memory data structure that can be thought of as extensible vector of JSON tokens. It is implemented as segmented sequence to allow for good performance characteristics for linear (in-order) reading (via iteration) and writing (append) of JSON tokens. Main use case is that of creating and filling a buffer instance, and then reading its contents one or more time, in order contents were appended. This is typically needed when processing data that arrives in order different from processing order.
Usage
TokenBuffer instances can be directly created:
TokenBuffer buffer = new TokenBuffer(null); // pass ObjectCodec (ObjectMapper) if you have one; don't construct)
and optional ObjectCodec instance is only relevant if using data-binding methods of JsonParser and JsonGenerator that need a codec (namely, JsonParser.readValueAs() and JsonGenerator.writeObject()).
TokenBuffer directly implements JsonGenerator, so it can be passed as one; for example, you can serialize a POJO as JSON tokens by:
objectMapper.writeValue(buffer, myPojo);
Contents can be read by creating a JsonParser from buffer:
JsonParser jp = buffer.asParser();
which can also be passed to other functionality.
TokenBuffer is used by mapper package for buffering in some cases; for example when processing JacksonFeatureCreators properties.
Back to Jackson Term Glossary
