Skip to main content

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:

AttributeDescription
addBeanTypesAdd _type properties to beans whose type can't be inferred through reflection (default false).
maxLengthMaximum wire-declared length (bytes) for binary and string payloads when parsing; guards against malicious length prefixes.
rankOrdering 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​