Package org.apache.juneau.marshall.cbor
Class CborParser
java.lang.Object
org.apache.juneau.marshall.Context
org.apache.juneau.marshall.MarshallingContextable
org.apache.juneau.marshall.parser.Parser
org.apache.juneau.marshall.parser.InputStreamParser
org.apache.juneau.marshall.cbor.CborParser
- All Implemented Interfaces:
CborMetaProvider,ArrayRecordReadable,RecordReadable,TokenReadable
- Direct Known Subclasses:
CborParser.Base64,CborParser.SpacedHex
public class CborParser
extends InputStreamParser
implements CborMetaProvider, TokenReadable, ArrayRecordReadable
Parses CBOR streams (RFC 8949) into POJO models.
Content-Type types: application/cbor
Media types
HandlesDescription
CBOR-to-Java type mapping:
- CBOR map (major type 5) → bean or
Map - CBOR array (major type 4) →
Collectionor Java array - CBOR text string (major type 3) →
String; coerced to types parseable from string - CBOR unsigned/negative integer (major types 0/1) →
IntegerorLong - CBOR float (major type 7, 0xFA/0xFB) →
FloatorDouble - CBOR half-precision float (major type 7, 0xF9) →
Float(converted) - CBOR boolean (major type 7, 0xF4/0xF5) →
Boolean - CBOR null (major type 7, 0xF6) →
null - CBOR byte string (major type 2) →
byte[] - CBOR semantic tag (major type 6) → tag ignored; tagged value parsed normally
Round-trip notes:
- Integers (major types 0/1) surface by target type: a
BigIntegerfield carries the full unsigned-64-bit magnitude; any other numeric type keeps the raw 64-bit bits as along. BigInteger/BigDecimalround-trip losslessly (big integers decode from native CBOR integers or, beyond±2^64, from their decimal string;BigDecimaldecodes from its decimal string).- Indefinite-length CBOR (RFC 8949 §3.2) is supported: arrays, maps, and chunked text/byte strings all decode.
- Semantic tags are read and discarded on the databind path; tag number does not affect parsed
type. Enable
nativeModeto surface tags/simple values on theTokenReadercursor.
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault parser, string input encoded as BASE64.static classBuilder class.static classDefault parser, string input encoded as spaced-hex.Nested classes/interfaces inherited from class org.apache.juneau.marshall.parser.InputStreamParser
InputStreamParser.DefaultBuilderNested classes/interfaces inherited from class org.apache.juneau.marshall.parser.Parser
Parser.Null -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CborParserDefault parser, all default settings.static final CborParserDefault parser, string input encoded as BASE64.static final CborParserDefault parser with binary-native opt-in mode enabled (CBOR tags / simple values surface as token-level metadata).static final CborParserDefault parser, string input encoded as spaced-hex.protected final booleanFields inherited from class org.apache.juneau.marshall.parser.Parser
autoCloseStreams, consumes, debugOutputLines, listener, nulls, trimStrings, unbufferedFields 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 CborParser.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.intReturns the maximum allowed wire-declared length for byte/text strings and array/map element counts.Returns a session to use for this context.booleanReturnstrue if token-cursor native mode is enabled.Returns the properties on this bean as a map for debugging.readArrayRecords(Object input) Convenience delegator for the streaming array-elementRecordReader(uses default session args; seereadTokens(Object)).readTokens(Object input) Convenience delegator that opens aCborTokenReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).Methods inherited from class org.apache.juneau.marshall.parser.InputStreamParser
getBinaryFormat, isReaderParserMethods inherited from class org.apache.juneau.marshall.parser.Parser
canHandle, createParserBuilder, doRead, getDebugOutputLines, getListener, getMediaTypes, getNulls, getPrimaryMediaType, isAutoCloseStreams, isTrimStrings, isUnbuffered, read, read, read, read, read, read, readArgs, readIntoCollection, readIntoMap, readWithOuterMethods 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.ArrayRecordReadable
isArrayRecordStreaming, readArrayRecordsMethods inherited from interface org.apache.juneau.marshall.stream.RecordReadable
isRecordStreamingMethods inherited from interface org.apache.juneau.marshall.stream.TokenReadable
readRecords
-
Field Details
-
DEFAULT
Default parser, all default settings. -
DEFAULT_NATIVE
Default parser with binary-native opt-in mode enabled (CBOR tags / simple values surface as token-level metadata). -
DEFAULT_SPACED_HEX
Default parser, string input encoded as spaced-hex. -
DEFAULT_BASE64
Default parser, string input encoded as BASE64. -
nativeMode
-
-
Constructor Details
-
CborParser
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
isNativeMode
Returnstrue if token-cursor native mode is enabled.- Returns:
true if native mode is enabled, elsefalse .
-
getMaxLength
Returns the maximum allowed wire-declared length for byte/text strings and array/map element counts.- Returns:
- The maximum length.
-
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.
-
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 classInputStreamParser- 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 classInputStreamParser- Returns:
- A new session object.
-
readTokens
Convenience delegator that opens aCborTokenReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).The real implementation lives on
CborParserSession.readTokens(Object). Callers that need request-derived configuration (locale, timezone, schema, swaps) should callcreateSession()and invokeCborParserSession.readTokens(Object)on the built session instead.- Specified by:
readTokensin interfaceTokenReadable- Parameters:
input- The input.- Returns:
- A new
CborTokenReader. - Throws:
IOException- If a problem occurred opening the underlying input.
-
readArrayRecords
Convenience delegator for the streaming array-elementRecordReader(uses default session args; seereadTokens(Object)). Real impl onCborParserSession.readArrayRecords(Object).- Specified by:
readArrayRecordsin interfaceArrayRecordReadable- Parameters:
input- The input.- Returns:
- A new element-streamed
RecordReader. - Throws:
IOException- If a problem occurred opening the underlying input.
-
properties
Description copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classParser- Returns:
- The properties on this bean as a map for debugging.
-