Feature: TokenBuffer for efficient buffering of parsed JSON content

(see Jira entry JACKSON-175 for details)

One use case that has become much more important over time is that where processing is done in multiple stages, and not in just one pass. One obvious example is that of pipelining multiple transformation tasks. Conceptually this can be done by parsing, modifying and writing JSON content; and repeating this multiple times. But since both parsing and generation are relatively expensive operations, it would be beneficial to have an intermediate representation that is equivalent to output of parsing, and that could be used as input for generator.

This is where TokenBuffer comes in. It is essentially a queue of JsonTokens with associated data. Given this, it is trivially easy to both build JsonParsers for "reading" through contents; as well as construct JsonGenerators that actually append to TokenBuffer instead of writing out JSON. And with these basic operations it is obviously also possible to do data binding to and from TokenBuffers as well as convert to/from Tree Model instances.

One side benefit of this new utility class is that ObjectMapper.convertValue() should now be quite efficient, since no actual JSON processing is needed: source object is just serialized into TokenBuffer, and result object is constructed out of this buffer.

Sample Code

Wouldn't it be nice to have examples of what kind of nifty things you can build using TokenBuffer? If you have such sample code, please share!


CategoryJackson

JacksonFeatureTokenBuffer (last edited 2010-03-13 01:24:43 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC