Class MsgPackSerializer
- All Implemented Interfaces:
Function<Object,,byte[]> ThrowingFunction<Object,,byte[]> MsgPackMetaProvider,ArrayRecordWritable,RecordWritable,TokenWritable
- Direct Known Subclasses:
MsgPackSerializer.Base64,MsgPackSerializer.SpacedHex
Media types:
Handles
Produces
The legacy media type
Description
Java-to-MessagePack type mapping:
- Maps and beans → MessagePack map type
- Collections and arrays → MessagePack array type
String/Enum→ MessagePack string typeBoolean→ MessagePack boolean typeNumber(int, long, float, double, etc.) → MessagePack number type (variable-length int or float)Date/Calendar/Instant→ ISO 8601 stringDuration→ ISO 8601 duration stringbyte[]→ MessagePack binary typenull→ MessagePack nil type- All other types → fallback to
toString()as string
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault serializer, BASE64 string output.static classBuilder class.static classDefault serializer, spaced-hex string output.Nested classes/interfaces inherited from class org.apache.juneau.marshall.serializer.OutputStreamSerializer
OutputStreamSerializer.DefaultBuilderNested classes/interfaces inherited from class org.apache.juneau.marshall.serializer.Serializer
Serializer.Null -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanstatic final MsgPackSerializerDefault serializer, all default settings.static final MsgPackSerializerDefault serializer, all default settings, spaced-hex string output.static final MsgPackSerializerDefault serializer, all default settings, spaced-hex string output.Fields inherited from class org.apache.juneau.marshall.serializer.Serializer
accept, addBeanTypes, addRootType, keepNullProperties, listener, nonDefault, produces, sortCollections, sortMaps, trimEmptyCollections, trimEmptyMaps, trimStringsFields inherited from class org.apache.juneau.marshall.MarshallingContextable
marshallingContextFields inherited from class org.apache.juneau.marshall.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a builder from this context object.static MsgPackSerializer.Buildercreate()Creates a new builder for this object.Create a session builder based on the properties defined on this context.Returns the language-specific metadata on the specified bean property.getMsgPackClassMeta(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.Returns a session to use for this context.protected final booleanAdd"_type" properties when needed.booleanStreaming-quality signal queryable before opening a cursor.Returns the properties on this bean as a map for debugging.writeArrayRecords(Object output) Convenience delegator for the buffered array-elementRecordWriter(uses default session args; seewriteTokens(Object)).writeArrayRecords(Object output, int expectedCount) Convenience delegator for the streaming, count-prefixed array-elementRecordWriter(uses default session args; seewriteTokens(Object)).writeTokens(Object output) Convenience delegator that opens aMsgPackTokenWriterover the output using default session arguments (mirrorsOutputStreamSerializer.write(Object)).Methods inherited from class org.apache.juneau.marshall.serializer.OutputStreamSerializer
applyThrows, getBinaryFormat, isWriterSerializer, writeMethods inherited from class org.apache.juneau.marshall.serializer.Serializer
createSerializerBuilder, doWrite, forEachAcceptMediaType, getListener, getMediaTypeRanges, getPrimaryMediaType, getResponseContentType, getResponseHeaders, getUriContext, getUriRelativity, getUriResolution, isAddRootType, isKeepNullProperties, isNonDefault, isSortCollections, isSortMaps, isTrimEmptyCollections, isTrimEmptyMaps, isTrimStrings, write, writeToStringMethods inherited from class org.apache.juneau.marshall.MarshallingTraverseContext
getDetectRecursions, getIgnoreRecursions, getInitialDepth, getMaxDepth, isDetectRecursions, isIgnoreRecursions, shouldDetectRecursionsMethods inherited from class org.apache.juneau.marshall.MarshallingContextable
getDurationFormat, getMarshallingContext, getPeriodFormatMethods inherited from class org.apache.juneau.marshall.Context
createBuilder, getAnnotationProvider, init, isDebug, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.marshall.stream.RecordWritable
isRecordStreamingMethods inherited from interface org.apache.juneau.commons.function.ThrowingFunction
applyMethods inherited from interface org.apache.juneau.marshall.stream.TokenWritable
writeRecords
-
Field Details
-
DEFAULT
Default serializer, all default settings. -
DEFAULT_SPACED_HEX
Default serializer, all default settings, spaced-hex string output. -
DEFAULT_BASE64
Default serializer, all default settings, spaced-hex string output. -
addBeanTypesMsgPack
-
-
Constructor Details
-
MsgPackSerializer
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
copy
Description copied from class:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
- Overrides:
copyin classSerializer- Returns:
- A new Builder object.
-
createSession
Description copied from class:ContextCreate a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use
Context.getSession()directly.- Overrides:
createSessionin classOutputStreamSerializer- Returns:
- A new session builder.
-
getMsgPackBeanPropertyMeta
Description copied from interface:MsgPackMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
getMsgPackBeanPropertyMetain interfaceMsgPackMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getMsgPackClassMeta
Description copied from interface:MsgPackMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
getMsgPackClassMetain interfaceMsgPackMetaProvider- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
getSession
Description copied from class:ContextReturns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Overrides:
getSessionin classOutputStreamSerializer- Returns:
- A new session object.
-
writeTokens
Convenience delegator that opens aMsgPackTokenWriterover the output using default session arguments (mirrorsOutputStreamSerializer.write(Object)).The real implementation lives on
MsgPackSerializerSession.writeTokens(Object). Callers that need request-derived configuration (locale, timezone, schema, swaps) should callcreateSession()and invokeMsgPackSerializerSession.writeTokens(Object)on the built session instead.- Specified by:
writeTokensin interfaceTokenWritable- Parameters:
output- The output.- Returns:
- A new
MsgPackTokenWriter. - Throws:
IOException- If the output type is not supported or could not be opened.
-
isAddBeanTypes
Description copied from class:SerializerAdd"_type" properties when needed.- Overrides:
isAddBeanTypesin classSerializer- Returns:
true if"_type" properties added to beans if their type cannot be inferred through reflection.- See Also:
-
properties
Description copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classSerializer- Returns:
- The properties on this bean as a map for debugging.
-
writeArrayRecords
Convenience delegator for the buffered array-elementRecordWriter(uses default session args; seewriteTokens(Object)). Real impl onMsgPackSerializerSession.writeArrayRecords(Object).- Specified by:
writeArrayRecordsin interfaceArrayRecordWritable- Parameters:
output- The output.- Returns:
- A buffered
RecordWriter. - Throws:
IOException- If a problem occurred opening the underlying output.
-
isArrayRecordStreaming
Description copied from interface:ArrayRecordWritableStreaming-quality signal queryable before opening a cursor.- Specified by:
isArrayRecordStreamingin interfaceArrayRecordWritable- Returns:
true for true element streaming (json/cbor/msgpack);false for the bufferedRecordAdapter.arrayWriter(org.apache.juneau.marshall.serializer.SerializerSession, java.lang.Object)-backed formats (yaml, parquet, bson).
-
writeArrayRecords
Convenience delegator for the streaming, count-prefixed array-elementRecordWriter(uses default session args; seewriteTokens(Object)). Real impl onMsgPackSerializerSession.writeArrayRecords(Object, int).- Specified by:
writeArrayRecordsin interfaceArrayRecordWritable- Parameters:
output- The output (must be anOutputStream).expectedCount- The number of elements that will be written.- Returns:
- A streaming
RecordWriter. - Throws:
IOException- If a problem occurred opening the underlying output.
-