MessagePack
Juneau supports converting arbitrary POJOs to and from MessagePack using ultra-efficient serializers and parsers. MessagePack is a compact binary form of JSON.
The serialization support for MessagePack mirrors that of JSON.
Media types
The serializer emits Content-Type: application/msgpack (the RFC 6838-conforming value, matching the constant
org.apache.juneau.http.header.ContentType.APPLICATION_MSGPACK).
The parser accepts both application/msgpack and the legacy octal/msgpack value as a backward-compatibility
alias, so payloads produced by earlier Juneau releases continue to decode without changes.
Annotations
@MsgPackConfig sets serializer/parser properties on a REST class or method (see Context Annotations). Attributes are strings:
| Attribute | Description |
|---|---|
addBeanTypes | Add _type properties to beans whose type can't be inferred through reflection (default false). |
maxLength | Maximum wire-declared length (bytes) for binary and string payloads when parsing; guards against malicious length prefixes. |
rank | Ordering relative to other config annotations. |
@Rest
@MsgPackConfig(maxLength="1048576")
public class MyResource extends BasicRestServlet { ... }
@MsgPack is a class/method/field marker (its only attribute is description),
and @MsgPackApply applies it to other
classes/members via on()/onClass() (see Dynamically Applied Annotations).
Token Streaming
MessagePack is a FULL-capability streaming format. The MsgPackParser implements TokenReadable and
ArrayRecordReadable; the MsgPackSerializer implements TokenWritable and ArrayRecordWritable.
This means you can read and write MessagePack using fine-grained structural token cursors in O(1) memory,
without materializing the entire document.
See Token-Streaming Basics for the full capability matrix and API overview,
Token Streaming for the TokenReader/TokenWriter API,
and Array-Record Streaming for element-by-element access over top-level arrays
(including the writeArrayRecords(output, expectedCount) streaming count overload for MsgPack).
In This Section
2.2.30.1. MessagePack Serializers
The MsgPackSerializer class is used to serialize POJOs
2.2.30.2. MessagePack Parsers
The MsgPackParser class is used to parse MessagePack into