Package com.upokecenter.cbor
Class JSONOptions
java.lang.Object
com.upokecenter.cbor.JSONOptions
Includes options to control how CBOR objects are converted to and from
JavaScript object Notation (JSON).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies how JSON numbers are converted to CBOR objects when decoding JSON (such as viaFromJSONStringorReadJSON). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JSONOptionsThe default options for converting CBOR objects to JSON. -
Constructor Summary
ConstructorsConstructorDescriptionInitializes a new instance of theJSONOptionsclass with default options.JSONOptions(boolean base64Padding) Deprecated.Use the more readable String constructor instead.JSONOptions(boolean base64Padding, boolean replaceSurrogates) Deprecated.JSONOptions(String paramString) Initializes a new instance of theJSONOptionsclass. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanGets a value indicating whether to allow duplicate keys when reading JSON.final booleanDeprecated.This property now has no effect.final booleanGets a value indicating whether to preserve the order in which a map's keys appear when decoding JSON, by using maps created as though by CBORObject.NewOrderedMap.Gets a value indicating how JSON numbers are decoded to CBOR objects.final booleanGets a value indicating whether the JSON decoder should preserve the distinction between positive zero and negative zero when the decoder decodes JSON to a floating-point number format that makes this distinction.final booleanGets a value indicating whether surrogate code points not part of a surrogate pair (which consists of two consecutivechars forming one Unicode code point) are each replaced with a replacement character (U+FFFD).final booleanGets a value indicating whether JSON is written using only code points from the Basic Latin block (U+0000 to U+007F), also known as ASCII.toString()Gets the values of this options object's properties in text form.
-
Field Details
-
Default
The default options for converting CBOR objects to JSON.
-
-
Constructor Details
-
JSONOptions
public JSONOptions()Initializes a new instance of theJSONOptionsclass with default options. -
JSONOptions
Deprecated.Use the more readable String constructor instead.Initializes a new instance of theJSONOptionsclass with the given value for the Base64Padding option.- Parameters:
base64Padding- Whether padding is included when writing data in base64url or traditional base64 format to JSON.
-
JSONOptions
Deprecated.Initializes a new instance of theJSONOptionsclass with the given values for the options.- Parameters:
base64Padding- Whether padding is included when writing data in base64url or traditional base64 format to JSON.replaceSurrogates- Whether surrogate code points not part of a surrogate pair (which consists of two consecutivechars forming one Unicode code point) are each replaced with a replacement character (U+FFFD). The default is false; an exception is thrown when such code points are encountered.
-
JSONOptions
Initializes a new instance of theJSONOptionsclass.- Parameters:
paramString- A string setting forth the options to use. This is a semicolon-separated list of options, each of which has a key and a value separated by an equal sign ("="). Whitespace and line separators are not allowed to appear between the semicolons or between the equal signs, nor may the string begin or end with whitespace. The string can be empty, but cannot be null. The following is an example of this parameter:base64padding = false;replacesurrogates = true. The key can be any one of the following where the letters can be any combination of basic upper-case and/or basic lower-case letters:base64padding,replacesurrogates,allowduplicatekeys,preservenegativezero,numberconversion,writebasic,keepkeyorder. Other keys are ignored in this version of the CBOR library. (Keys are compared using a basic case-insensitive comparison, in which two strings are equal if they match after converting the basic upper-case letters A to Z (U+0041 to U+005A) in both strings to basic lower-case letters.) If two or more key/value pairs have equal keys (in a basic case-insensitive comparison), the value given for the last such key is used. The first four keys just given can have a value of1,true,yes, oron(where the letters can be any combination of basic upper-case and/or basic lower-case letters), which means true, and any other value meaning false. The last key,numberconversion, can have a value of any name given in theJSONOptions.ConversionModeenumeration (where the letters can be any combination of basic upper-case and/or basic lower-case letters), and any other value is unrecognized. (If thenumberconversionkey is not given, its value is treated asfull. If that key is given, but has an unrecognized value, an exception is thrown.) For example,base64padding = Yesandbase64padding = 1both set theBase64Paddingproperty to true, andnumberconversion = doublesets theNumberConversionproperty toConversionMode.Double.- Throws:
NullPointerException- The parameterparamStringis null. In the future, this class may allow other keys to store other kinds of values, not just true or false.IllegalArgumentException- An unrecognized value fornumberconversionwas given.
-
-
Method Details
-
toString
Gets the values of this options object's properties in text form. -
getBase64Padding
Deprecated.This property now has no effect. This library now includes necessary padding when writing traditional base64 to JSON and includes no padding when writing base64url to JSON, in accordance with the revision of the CBOR specification.Gets a value indicating whether the Base64Padding property is true. This property has no effect; in previous versions, this property meant that padding was written out when writing base64url or traditional base64 to JSON.- Returns:
- A value indicating whether the Base64Padding property is true.
-
getPreserveNegativeZero
public final boolean getPreserveNegativeZero()Gets a value indicating whether the JSON decoder should preserve the distinction between positive zero and negative zero when the decoder decodes JSON to a floating-point number format that makes this distinction. For a value offalse, if the result of parsing a JSON string would be a floating-point negative zero, that result is a positive zero instead. (Note that this property has no effect for conversion kindIntOrFloatFromDouble, where floating-point zeros are not possible.).- Returns:
- A value indicating whether to preserve the distinction between positive zero and negative zero when decoding JSON. The default is true.
-
getNumberConversion
Gets a value indicating how JSON numbers are decoded to CBOR objects. None of the conversion modes affects how CBOR objects are later encoded (such as viaEncodeToBytes).- Returns:
- A value indicating how JSON numbers are decoded to CBOR. The default
is
ConversionMode.Full.
-
getWriteBasic
public final boolean getWriteBasic()Gets a value indicating whether JSON is written using only code points from the Basic Latin block (U+0000 to U+007F), also known as ASCII.- Returns:
- A value indicating whether JSON is written using only code points from the Basic Latin block (U+0000 to U+007F), also known as ASCII. Default is false.
-
getKeepKeyOrder
public final boolean getKeepKeyOrder()Gets a value indicating whether to preserve the order in which a map's keys appear when decoding JSON, by using maps created as though by CBORObject.NewOrderedMap. If false, key order is not guaranteed to be preserved when decoding JSON.- Returns:
- A value indicating whether to preserve the order in which a CBOR map's keys appear when decoding JSON. The default is false.
-
getAllowDuplicateKeys
public final boolean getAllowDuplicateKeys()Gets a value indicating whether to allow duplicate keys when reading JSON. Used only when decoding JSON. If this property istrueand a JSON object has two or more values with the same key, the last value of that key set forth in the JSON object is taken.- Returns:
- A value indicating whether to allow duplicate keys when reading JSON. The default is false.
-
getReplaceSurrogates
public final boolean getReplaceSurrogates()Gets a value indicating whether surrogate code points not part of a surrogate pair (which consists of two consecutivechars forming one Unicode code point) are each replaced with a replacement character (U+FFFD). If false, an exception is thrown when such code points are encountered.- Returns:
- True, if surrogate code points not part of a surrogate pair are each replaced with a replacement character, or false if an exception is thrown when such code points are encountered. The default is false.
-