Interface TokenWriter

All Superinterfaces:
AutoCloseable, Closeable, Flushable, RecordWriter
All Known Implementing Classes:
CborTokenWriter, JsonlTokenWriter, JsonTokenWriter, MsgPackTokenWriter

public interface TokenWriter extends RecordWriter
Public low-level push-generator that emits a Juneau-formatted document one structural event at a time.

The caller emits structural events (startObject() / fieldName(String) / number(long) / ...) and the implementation produces the corresponding bytes for its format. This is a format-neutral surface; the same writer methods work across every Juneau format that implements TokenWritable (the structural-token role).

Usage:

StringBuilder sb = new StringBuilder(); try (TokenWriter w = Json.DEFAULT.writeTokens(sb)) { w.startObject(); w.fieldName("a"); w.number(1); w.fieldName("b"); w.startArray(); w.bool(true); w.nil(); w.endArray(); w.endObject(); } // sb is now: {"a":1,"b":[true,null]}

Contract:
  • The writer is purely structural. It bypasses object swaps and @Schema annotations — that is the role of the POJO databind path on Serializer and its bridges.
  • It is the caller's responsibility to emit a well-formed event sequence (every startObject() matched by an endObject(), every field name followed by exactly one value or container, etc.). Implementations are not required to validate the sequence, though they may.
  • Concrete implementations are not required to be thread-safe.
See Also: