Class CborSerializer
- All Implemented Interfaces:
Function<Object,,byte[]> ThrowingFunction<Object,,byte[]> CborMetaProvider,ArrayRecordWritable,RecordWritable,TokenWritable
- Direct Known Subclasses:
CborSerializer.Base64,CborSerializer.SpacedHex
Media types:
Handles
Produces
Description
Java-to-CBOR type mapping:
- Maps and beans → CBOR map (major type 5)
- Collections and arrays → CBOR array (major type 4)
String/Enum→ CBOR text string (major type 3, UTF-8)Boolean→ CBOR simple values 20/21 (0xF4 /0xF5 )Number(int, long, float, double) → CBOR compact integers (major types 0/1) or IEEE 754 floats (major type 7)Date/Calendar/Instant→ ISO 8601 stringDuration→ ISO 8601 duration stringbyte[]→ CBOR byte string (major type 2)null→ CBOR simple value 22 (0xF6 )- All other types → fallback to
toString()as string
Behavior-specific subclasses:
CborSerializer.SpacedHex— Spaced-hex text output for debuggingCborSerializer.Base64— Base64 text output
Example:
Round-trip notes:
BigInteger— emitted losslessly as a native CBOR integer when it fits CBOR's integer range (-2^64 .. 2^64-1), otherwise as a lossless decimal string.BigDecimal— emitted as a lossless decimal string (native CBOR has no decimal number head without semantic tags).- The high-level databind path emits definite-length containers; the streaming
CborTokenWriteremits indefinite-length containers (both are valid RFC 8949). - Half-precision float (0xF9) not produced; always uses float32 (0xFA) or float64 (0xFB).
- Semantic tags (major type 6) not emitted unless
useTags(true).
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 CborSerializerDefault serializer, all default settings.static final CborSerializerDefault serializer, BASE64 string output.static final CborSerializerDefault serializer, spaced-hex string output.protected final booleanFields 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 CborSerializer.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.getCborClassMeta(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.Returns the properties on this bean as a map for debugging.writeArrayRecords(Object output) Convenience delegator for the streaming array-elementRecordWriter(uses default session args; seewriteTokens(Object)).writeTokens(Object output) Convenience delegator that opens aCborTokenWriterover 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.ArrayRecordWritable
isArrayRecordStreaming, writeArrayRecordsMethods 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, spaced-hex string output. -
DEFAULT_BASE64
Default serializer, BASE64 string output. -
addBeanTypesCbor
-
useTags
-
-
Constructor Details
-
CborSerializer
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.
-
getCborBeanPropertyMeta
Description copied from interface:CborMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
getCborBeanPropertyMetain interfaceCborMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getCborClassMeta
Description copied from interface:CborMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
getCborClassMetain interfaceCborMetaProvider- 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 aCborTokenWriterover the output using default session arguments (mirrorsOutputStreamSerializer.write(Object)).The real implementation lives on
CborSerializerSession.writeTokens(Object). Callers that need request-derived configuration (locale, timezone, schema, swaps) should callcreateSession()and invokeCborSerializerSession.writeTokens(Object)on the built session instead.- Specified by:
writeTokensin interfaceTokenWritable- Parameters:
output- The output. AcceptsOutputStreamorFile.- Returns:
- A new
CborTokenWriter. - 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 streaming array-elementRecordWriter(uses default session args; seewriteTokens(Object)). Real impl onCborSerializerSession.writeArrayRecords(Object).- Specified by:
writeArrayRecordsin interfaceArrayRecordWritable- Parameters:
output- The output.- Returns:
- A new element-streamed
RecordWriter. - Throws:
IOException- If a problem occurred opening the underlying output.
-