Class JSONOptions

java.lang.Object
com.upokecenter.cbor.JSONOptions

public final class JSONOptions extends Object
Includes options to control how CBOR objects are converted to and from JavaScript object Notation (JSON).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Specifies how JSON numbers are converted to CBOR objects when decoding JSON (such as via FromJSONString or ReadJSON).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final JSONOptions
    The default options for converting CBOR objects to JSON.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the JSONOptions class 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 the JSONOptions class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Gets a value indicating whether to allow duplicate keys when reading JSON.
    final boolean
    Deprecated.
    This property now has no effect.
    final boolean
    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.
    Gets a value indicating how JSON numbers are decoded to CBOR objects.
    final boolean
    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.
    final boolean
    Gets a value indicating whether surrogate code points not part of a surrogate pair (which consists of two consecutive char s forming one Unicode code point) are each replaced with a replacement character (U+FFFD).
    final boolean
    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.
    Gets the values of this options object's properties in text form.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • Default

      public static final JSONOptions Default
      The default options for converting CBOR objects to JSON.
  • Constructor Details

    • JSONOptions

      public JSONOptions()
      Initializes a new instance of the JSONOptions class with default options.
    • JSONOptions

      @Deprecated public JSONOptions(boolean base64Padding)
      Deprecated.
      Use the more readable String constructor instead.
      Initializes a new instance of the JSONOptions class 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 public JSONOptions(boolean base64Padding, boolean replaceSurrogates)
      Deprecated.
      Initializes a new instance of the JSONOptions class 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 consecutive char s 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

      public JSONOptions(String paramString)
      Initializes a new instance of the JSONOptions class.
      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 of 1, true, yes, or on (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 the JSONOptions.ConversionMode enumeration (where the letters can be any combination of basic upper-case and/or basic lower-case letters), and any other value is unrecognized. (If the numberconversion key is not given, its value is treated as full. If that key is given, but has an unrecognized value, an exception is thrown.) For example, base64padding = Yes and base64padding = 1 both set the Base64Padding property to true, and numberconversion = double sets the NumberConversion property to ConversionMode.Double .
      Throws:
      NullPointerException - The parameter paramString is 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 for numberconversion was given.
  • Method Details

    • toString

      public String toString()
      Gets the values of this options object's properties in text form.
      Overrides:
      toString in class Object
      Returns:
      A text string containing the values of this options object's properties. The format of the string is the same as the one described in the string constructor for this class.
    • getBase64Padding

      @Deprecated public final boolean 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 of false, 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 kind IntOrFloatFromDouble, 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

      public final JSONOptions.ConversionMode 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 via EncodeToBytes).
      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 is true and 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 consecutive char s 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.