org.coursera.courier.codecs

InlineStringCodec

class InlineStringCodec extends DataCodec

Provides a URL "Friendly" string encoding of data.

This encoding aims to strike a balance between:

- Safety, convenience and brevity when used on the URL - JSON equivalence

To that end, this encoding:

- Guarantees that equivalent data is also string equivalent. - Does not use any URL reserved chars in the core syntax. - Does not require quoting of string primitives.

In order to achieve this, the encoding has a few constraints:

- All map keys must be sorted in alpha-numeric order for serialization. - Extraneous whitespace is not allowed. - Primitives must be represented in "canonical form". For example there may be no leading or trailing zeros on numeric types.

This encoding also has a few limitations:

- Serialized data must be URL encoded before being used in URLs, but only to escape chars that might appear in string literals. - It is lossy: All primitives types are downgraded to plain strings, but can be "fixed-up", this is explained in detail below. - An array containing a single empty string ([""] in JSON), has the special representation of List(~) in this format. This is to prevent an ambiguity between an empty list and a list containing a single empty string.

JSON Encoding | Inline String Encoding ----------------------------------|--------------------------------------- { "a": "one", "b": "two"} | (a~one,b~two) [1, 2, 3] | List(1,2,3) { "ids": [1,2], "score": 3.14 } | (ids~List(1,2),score~3.14)

Escaping:

When used in strings the reserved chars (),~! must be escaped by prefixing them with !.

JSON Encoding | Inline String Encoding -------------------------------------|--------------------------------------- { "string": "~An (odd) string !" } | (string~!~An !(odd!) string !!)

Fix up:

Pegasus provides "Fix-up" to convert plain strings used in this format back to their correct primitive types. It is recommended that fix-up be run on all data deserialized from this format, e.g.:

val validationResult =
  ValidateDataAgainstSchema.validate(
    dataMap,
    schema,
    new ValidationOptions(
      RequiredMode.FIXUP_ABSENT_WITH_DEFAULT,
      CoercionMode.STRING_TO_PRIMITIVE))
if (validationResult.isValid) {
  // The data map is now fixed up, if it has been marked as ReadOnly,
  // use validationResult.getFixed to get the fixed-up copy, otherwise dataMap
  // will be fixed up in-place.
}
Linear Supertypes
DataCodec, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. InlineStringCodec
  2. DataCodec
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new InlineStringCodec()

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def bytesToList(bytes: Array[Byte]): DataList

    Definition Classes
    InlineStringCodec → DataCodec
  8. def bytesToMap(bytes: Array[Byte]): DataMap

    Definition Classes
    InlineStringCodec → DataCodec
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. def listToBytes(dataList: DataList): Array[Byte]

    Definition Classes
    InlineStringCodec → DataCodec
  17. def mapToBytes(dataMap: DataMap): Array[Byte]

    Definition Classes
    InlineStringCodec → DataCodec
  18. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  21. def readList(inputStream: InputStream): DataList

    Definition Classes
    InlineStringCodec → DataCodec
  22. def readMap(inputStream: InputStream): DataMap

    Definition Classes
    InlineStringCodec → DataCodec
  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  24. def toString(): String

    Definition Classes
    AnyRef → Any
  25. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. def writeList(dataList: DataList, outputStream: OutputStream): Unit

    Definition Classes
    InlineStringCodec → DataCodec
  29. def writeMap(dataMap: DataMap, outputStream: OutputStream): Unit

    Definition Classes
    InlineStringCodec → DataCodec

Inherited from DataCodec

Inherited from AnyRef

Inherited from Any

Ungrouped