Class CBORTypeMapper

java.lang.Object
com.upokecenter.cbor.CBORTypeMapper

public final class CBORTypeMapper extends Object
Holds converters to customize the serialization and deserialization behavior of CBORObject.FromObject and CBORObject#ToObject, as well as type filters for ToObject.
  • Constructor Details

    • CBORTypeMapper

      public CBORTypeMapper()
      Initializes a new instance of the CBORTypeMapper class.
  • Method Details

    • AddConverter

      public <T> CBORTypeMapper AddConverter(Type type, ICBORConverter<T> converter)
      Registers an object that converts objects of a given type to CBOR objects (called a CBOR converter). If the CBOR converter converts to and from CBOR objects, it should implement the ICBORToFromConverter interface and provide ToCBORObject and FromCBORObject methods. If the CBOR converter only supports converting to (not from) CBOR objects, it should implement the ICBORConverter interface and provide a ToCBORObject method.
      Type Parameters:
      T - Must be the same as the "type" parameter.
      Parameters:
      type - A Type object specifying the type that the converter converts to CBOR objects.
      converter - The parameter converter is an ICBORConverter object.
      Returns:
      This object.
      Throws:
      NullPointerException - The parameter type or converter is null.
      IllegalArgumentException - Converter doesn't contain a proper ToCBORObject method".
    • FilterTypeName

      public boolean FilterTypeName(String typeName)
      Returns whether the given Java or.NET type name fits the filters given in this mapper.
      Parameters:
      typeName - The fully qualified name of a Java or.NET class (e.g., java.math.BigInteger or System.Globalization.CultureInfo).
      Returns:
      Either true if the given Java or.NET type name fits the filters given in this mapper, or false otherwise.
    • AddTypePrefix

      public CBORTypeMapper AddTypePrefix(String prefix)
      Adds a prefix of a Java or.NET type for use in type matching. A type matches a prefix if its fully qualified name is or begins with that prefix, using codepoint-by-codepoint (case-sensitive) matching.
      Parameters:
      prefix - The prefix of a Java or.NET type (e.g., `java.math.` or `System.Globalization`).
      Returns:
      This object.
      Throws:
      NullPointerException - The parameter prefix is null.
      IllegalArgumentException - The parameter prefix is empty.
    • AddTypeName

      public CBORTypeMapper AddTypeName(String name)
      Adds the fully qualified name of a Java or.NET type for use in type matching.
      Parameters:
      name - The fully qualified name of a Java or.NET class (e.g., java.math.BigInteger or System.Globalization.CultureInfo).
      Returns:
      This object.
      Throws:
      NullPointerException - The parameter name is null.
      IllegalArgumentException - The parameter name is empty.