public final class CborSimple extends CborObject
CborMajorType.OTHER and contain no additional data.
Untagged instances are always singletons, so you may directly compare known-untagged instances
(like TRUE, NULL, etc,) to any other CborSimple instance using just the
== operator. The equals(Object) method, of course, will also work, too.
On the other hand, tagged instances are not singletons. If you need to compare two unknown
CborSimple objects then you must use equals(Object).
| Modifier and Type | Field and Description |
|---|---|
static CborSimple |
FALSE
CBOR simple value constant instance for "false".
|
static CborSimple |
NULL
CBOR simple value constant instance for "null".
|
static CborSimple |
TRUE
CBOR simple value constant instance for "true".
|
static CborSimple |
UNDEFINED
CBOR simple value constant instance for "undefined" values.
|
| Modifier and Type | Method and Description |
|---|---|
CborSimple |
copy()
Creates an independent, deep copy of this data item.
|
static CborSimple |
create(int value)
Method for obtaining an untagged singleton instance for "simple values" that contains no
data.
|
static CborSimple |
create(int value,
int tag)
Method for obtaining a tagged instance for "simple values" that contains no data.
|
boolean |
equals(Object obj) |
int |
getAdditionalInformation()
Returns the object's "additional information" value.
|
int |
getMajorType()
Returns the object's "Major Type", as defined by RFC7049.
|
int |
getTag()
Returns the tag for this object.
|
int |
getValue()
Returns the "simple value" associated with this object.
|
int |
hashCode() |
boolean |
isValidJson()
Indicates if this data item can be losslessly converted to a JSON fragment.
|
@Nullable Object |
toJavaObject()
Converts the given data item into a standard java object representation.
|
<T> T |
toJavaObject(Class<T> clazz)
Attempts to convert this data item to a java object with a specific class.
|
String |
toJsonString()
Returns a representation of this data item as JSON text.
|
String |
toString()
Describes this data item using CBOR diagnostic notation.
|
String |
toString(int ignore)
Describes this data item using CBOR diagnostic notation at the given indentation level.
|
createFromCborByteArray, createFromCborByteArray, createFromJavaObject, toCborByteArraypublic static final CborSimple TRUE
public static final CborSimple FALSE
public static final CborSimple NULL
public static final CborSimple UNDEFINED
public static CborSimple create(int value, int tag)
tag is CborTag.UNTAGGED, then this method will return a singleton.
Otherwise it will return a newly allocated instance.value - the "simple value" of the desired singleton CborSimple object. Must be
in the range of 0 to 255, inclusive.tag - the value of the tagCborSimple object with the given value and tag.IllegalArgumentException - if value is out of range or if tag
is invalid.public static CborSimple create(int value)
value - the "simple value" of the desired singleton CborSimple object. Must be
in the range of 0 to 255, inclusive. Note that values in the range of 24..31 are reserved
and cannot be used.CborSimple object with the given value.IllegalArgumentException - if value is out of range or if it lies in the
reserved range of 24..31.public final int getMajorType()
CborObjectgetMajorType in class CborObjectCborMajorType,
CborObject.getAdditionalInformation()public final int getAdditionalInformation()
CborObjectgetAdditionalInformation in class CborObjectCborObject.getMajorType()public int getValue()
public int getTag()
CborObjectIf the object is not tagged, returns CborTag.UNTAGGED.
getTag in class CborObjectCborTag.UNTAGGED if
untagged.CborTagpublic CborSimple copy()
CborObjectcopy in class CborObjectCborObjectpublic final boolean isValidJson()
CborObjectNote that, with few exceptions, tags are not considered in this determination, since CborObject.toJsonString()
will strip out tags anyway.
isValidJson in class CborObjecttrue if this object could be rendered as JSON, false otherwise.public final String toJsonString()
CborObjectThe result is guaranteed to be syntactically-valid RFC8259 JSON text. In the event that there is
no JSON text representation for the underlying data item, its value will be replaced with a
placeholder JSON value (usually "null"). This condition can be detected beforehand
using CborObject.isValidJson().
Note that, in some pre-RFC8259 contexts, this method could be described as returning a
"JSON fragment" unless the data item was of the types CborMap (for a JSON
object) or CborArray (for a JSON array).
toJsonString in class CborObjectString containing representation of this data item as JSON textCborObject.isValidJson(),
RFC8259public @Nullable Object toJavaObject()
CborObjectTags are largely ignored, except in cases where the tag itself has defined behavior when
converting to JSON, like CborTag.EXPECTED_BASE16 and CborTag.EXPECTED_BASE64.
The resulting object type is dependent on the data item:
CborMap → Map<Object,Object>
CborArray → Collection<Object>
CborFloat → Float/Double
CborInteger → Integer/Long
CborTextString → String
CborByteString → byte[]
TRUE/FALSE → Boolean
CborSimple values → null
The returned value is a wholly independent copy.
toJavaObject in class CborObjectCborObject.createFromJavaObject(Object)public <T> T toJavaObject(Class<T> clazz) throws CborConversionException
CborObjectUnlike CborObject.toJavaObject(), this method will introspect into tags to figure out
conversions to BigInteger and URI. Unknown tags are ignored.
This method will return the most expressive result that satisfies the clazz
parameter. For example, if the data item is a CborByteString tagged CborTag.BIGNUM_POS, calling this method with different classes will lead to different
results:
toJavaObject(byte[].class would return a byte[]
toJavaObject(Object.class would return a BigInteger
toJavaObject(BigInteger.class would return a BigInteger
toJavaObject(URI.class would throw CborConversionException
Whereas this method called an untagged CborByteString would behave like this:
toJavaObject(byte[].class would return a byte[]
toJavaObject(Object.class would return a byte[]
toJavaObject(BigInteger.class would throw CborConversionException
toJavaObject(URI.class would throw CborConversionException
toJavaObject in class CborObjectclazz - The desired class of the returned objectclazz or null if this data item was
NULL or UNDEFINED.CborConversionException - if the underlying data item could not be represented as an
instance of clazz.public String toString(int ignore)
CborObjectThe output is similar to that of CborObject.toJsonString() except that it also includes tag
and encoding information that is CBOR-specific.
The returned string is intended as a diagnostic aid and not intended to be machine-readable.
toString in class CborObjectignore - the indentation level of the string to output. A negative value
indicates no newlines or whitespace should be added.String describing the data item.CborObject.toString()public final String toString()
CborObjectNo additional whitespace is added for readability.
The output is similar to that of CborObject.toJsonString() except that it also includes tag
and encoding information that is CBOR-specific.
The returned string is intended as a diagnostic aid and not intended to be machine-readable.
toString in class CborObjectString describing the data item.CborObject.toString(int)Copyright © 2018–2023. All rights reserved.