Packages

p

com.avsystem.commons

serialization

package serialization

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. abstract class ApplyUnapplyCodec[T] extends OOOFieldsObjectCodec[T] with ErrorReportingCodec[T]
  2. final class DefaultCaseObjectInput extends ObjectInput
  3. trait ErrorReportingCodec[T] extends GenCodec[T]
  4. trait FieldInput extends Input

    An Input representing an object field.

    An Input representing an object field. The same as Input but also provides field name.

  5. final class FieldValues extends AnyRef
  6. abstract class FlatSealedHierarchyCodec[T] extends SealedHierarchyCodec[T]
  7. case class GenCaseInfo[T](flags: TypeFlags, sourceName: String, annotName: commons.Opt[name], transparent: Boolean, defaultCase: Boolean) extends GenCodecStructure[T] with Product with Serializable
    Annotations
    @positioned( point = positioned.here )
  8. trait GenCodec[T] extends AnyRef

    Type class for types that can be serialized to Output (format-agnostic "output stream") and deserialized from Input (format-agnostic "input stream").

    Type class for types that can be serialized to Output (format-agnostic "output stream") and deserialized from Input (format-agnostic "input stream"). GenCodec is supposed to capture generic structure of serialized objects, without being bound to particular format like JSON. The actual format is determined by implementation of Input and Output.

    There are convenient macros for automatic derivation of GenCodec instances (materialize and materializeRecursively). However, GenCodec instances still need to be explicitly declared and won't be derived "automagically".

    Annotations
    @implicitNotFound( "No GenCodec found for ${T}" )
  9. sealed trait GenCodecStructure[T] extends GenInfo[T]
  10. sealed trait GenInfo[T] extends TypedMetadata[T]
  11. trait GenKeyCodec[T] extends AnyRef

    Typeclass which implements two-directional conversion between values of some type and field names used in ObjectOutput.writeField and ObjectInput.nextField (FieldInput.fieldName).

    Typeclass which implements two-directional conversion between values of some type and field names used in ObjectOutput.writeField and ObjectInput.nextField (FieldInput.fieldName). Every type which has a natural, unambiguous string representation should have a GenKeyCodec.

    Annotations
    @implicitNotFound( ... )
  12. case class GenParamInfo[T](sourceName: String, annotName: commons.Opt[name], hasWhenAbsent: Boolean, transientDefault: Boolean, outOfOrder: Boolean, flags: ParamFlags) extends GenInfo[T] with Product with Serializable
  13. case class GenRef[-S, +T](fun: (S) ⇒ T, rawRef: RawRef) extends Product with Serializable
  14. case class GenUnionInfo[T](flags: TypeFlags, sourceName: String, annotName: commons.Opt[name], flatten: commons.Opt[flatten]) extends GenCodecStructure[T] with Product with Serializable
    Annotations
    @positioned( point = positioned.here )
  15. abstract class HasGenCodec[T] extends AnyRef

    Convenience abstract class for companion objects of types that have a GenCodec.

  16. trait Input extends Any

    Represents an abstract source from which a value may be deserialized (read).

    Represents an abstract source from which a value may be deserialized (read). Each of the read methods tries to read a value of specified type and may throw an exception (usually ReadFailure) when reading is not successful.

    An Input value should be assumed to be stateful. If any of the readX methods have already been called, the Input instance can no longer be used and MUST be discarded.

    In order to ignore the value kept in this Input, skip() MUST be called.

    In summary: every Input MUST be fully exhausted by either calling one of the read methods which returns successful value or by calling skip(). Also, ListInput and ObjectInput instances returned from this Input must also be fully exhausted on their own.

  17. trait ListInput extends SequentialInput

    Represents an abstract source of sequence of values that can be deserialized.

    Represents an abstract source of sequence of values that can be deserialized. ListInput instance is stateful and MUST be read strictly sequentially. This means, you MUST fully exhaust an Input instance returned by nextElement() before calling nextElement() again. For this reason, ListInput is not an Iterator despite having similar interface (Iterator would easily allow e.g. conversion to List[Input] which would be illegal).

    ListInput MUST always be fully exhausted. In order to ignore any remaining elements, skipRemaining() may be used.

  18. trait ListOutput extends SequentialOutput

    Represents an abstract sink for serialization of sequences of values.

    Represents an abstract sink for serialization of sequences of values. Any ListOutput instance must be assumed to be stateful and used in strictly sequential manner. After all elements have been written, finish() must be called to explicitly mark that the list is complete.

  19. abstract class NestedSealedHierarchyCodec[T] extends SealedHierarchyCodec[T]
  20. trait ObjectInput extends SequentialInput

    Represents an abstract source of key-value mappings that can be deserialized.

    Represents an abstract source of key-value mappings that can be deserialized. ObjectInput instance is stateful and MUST be read strictly sequentially. This means, you MUST fully exhaust any Input instance returned by nextField() before calling nextField() again. For this reason, ObjectInput is not an Iterator despite having similar interface (Iterator would easily allow e.g. conversion to List[(String, Input)] which would be illegal).

    ObjectInput MUST always be fully exhausted. In order to ignore any remaining key-value mappings, skipRemaining() may be used.

  21. final class ObjectInputAsInput extends Input
  22. trait ObjectOutput extends SequentialOutput

    Represents an abstract sink for serialization of string-to-value mappings.

    Represents an abstract sink for serialization of string-to-value mappings. Any ObjectOutput instance must be assumed to be stateful and used in strictly sequential manner. After all key-value pairs have been written, finish() must be called to explicitly mark that the object is complete.

    ObjectOutput MUST preserve information about the order in which fields are written. ObjectInput is required to read fields in exactly the same order as ObjectOutput writes them.

  23. final class ObjectOutputAsOutput extends Output
  24. trait Output extends Any

    Represents an abstract sink to which a value may be serialized (written).

    Represents an abstract sink to which a value may be serialized (written). An Output instance should be assumed to be stateful. After calling any of the write methods, it MUST NOT be reused. This means that Output instance can be used only to write a single value. However, if the value to write is complex, one can use writeList/writeSet or writeObject/writeMap.

  25. final class PeekingObjectInput extends ObjectInput

    Wrapper over ObjectInput that lets you peek next field name without advancing the input.

  26. abstract class ProductCodec[T <: Product] extends ApplyUnapplyCodec[T]
  27. sealed trait RawRef extends AnyRef
  28. trait RecursiveAutoCodecs extends AnyRef
  29. abstract class SealedHierarchyCodec[T] extends ObjectCodec[T] with ErrorReportingCodec[T]
  30. trait SequentialInput extends Any
  31. trait SequentialOutput extends Any

    Base trait for outputs which allow writing of multiple values in sequence, i.e.

    Base trait for outputs which allow writing of multiple values in sequence, i.e. ListOutput and ObjectOutput.

  32. sealed trait SimpleRawRef extends RawRef
  33. class SimpleValueFieldInput extends SimpleValueInput with FieldInput
  34. class SimpleValueInput extends Input

    An Input for GenCodec complementary to SimpleValueOutput.

  35. class SimpleValueOutput extends Output

    An Output for GenCodec which serializes data into plain Scala objects.

    An Output for GenCodec which serializes data into plain Scala objects.

    - "lists" are represented as Scala Lists - "objects" are represented as String-keyed Scala Maps - simple values (strings, numbers, booleans, byte arrays) are represented as themselves, unchanged

    In other words, serialized value yield by SimpleValueOutput is a Scala object guaranteed to be one of: - null - Int - Long - Double - BigInt - BigDecimal - Boolean - String - Array[Byte] - scala.collection.Seq[Any] where every element is also one of the listed types - scala.collection.Map[String,Any] where every value is also one of the listed types

    Such format is often useful as an intermediate representation. For example, it can be later safely passed to standard Java serialization. However, for performance reasons it's recommended to implement dedicated Input and Output for the final format (e.g. binary or JSON).

  36. class SingletonCodec[T <: Singleton] extends OOOFieldsObjectCodec[T] with ErrorReportingCodec[T]
  37. class StreamFieldInput extends StreamInput with FieldInput
  38. class StreamInput extends Input
  39. class StreamOutput extends Output
  40. abstract class StringWrapperCompanion[T] extends TransparentWrapperCompanion[String, T]
  41. abstract class TransparentCodec[T, U] extends ErrorReportingCodec[T]
  42. abstract class TransparentWrapperCompanion[R, T] extends AnyRef
  43. trait TupleGenCodecs extends AnyRef
  44. class defaultCase extends Annotation with StaticAnnotation

    When materializing a GenCodec for sealed hierarchy with @flatten annotation, you can use this annotation on one of case classes or objects to mark it as the default one.

    When materializing a GenCodec for sealed hierarchy with @flatten annotation, you can use this annotation on one of case classes or objects to mark it as the default one. If during deserialization the codec is unable to find the _case field and determine the case class/object to deserialize, it will try to deserialize the data to the class/object marked with this annotation.

    This is useful for retaining backwards compatibility with serialized format when refactoring code and replacing a simple case class with a sealed hierarchy.

  45. class flatten extends Annotation with StaticAnnotation

    Changes the serialization format used by GenCodecs automatically derived for sealed hierarchies.

    Changes the serialization format used by GenCodecs automatically derived for sealed hierarchies. The format is changed from "nested" to "flat".

    @flatten sealed trait Value
    case class Numeric(int: Int) extends Value
    case class Textual(string: String) extends Value
    object Value {
      implicit val codec: GenCodec[Value] = GenCodec.materialize[Value]
    }

    Without flatten annotation, the "nested" format is used, e.g. when Numeric(42) would be encoded to JSON as:

    {"Numeric": {"int": 42}}

    but when flatten annotation is applied on sealed trait/class, then it changes to:

    {"_case": "Numeric", "int": 42}

    The "_case" field name can be customized with annotation parameter

  46. class generated extends Annotation with StaticAnnotation

    May be used on members of objects, case classes or any types having companion object with case class like apply and unapply/unapplySeq methods in order to add additional, generated fields to data serialized by auto-materialized GenCodecs.

    May be used on members of objects, case classes or any types having companion object with case class like apply and unapply/unapplySeq methods in order to add additional, generated fields to data serialized by auto-materialized GenCodecs.

    case class User(id: Long, login: String) {
      @generated def upperLogin: String = login.toUpperCase
    }
    object User {
      implicit val codec: GenCodec[User] = GenCodec.materialize[User]
    }

    This annotation may be applied on vals, vars and defs. When applied on a def, it must be either parameterless (no parameter lists or empty parameter list) or accept only implicit parameters, provided that all the implicit values are available in the scope where GenCodec is materialized (implicit values will be "baked in" the codec).

    NOTE: @generated annotation may be defined on any level of inheritance hierarchy - it will be inherited from implemented and overridden members.

  47. class name extends Annotation with StaticAnnotation with NotInheritedFromSealedTypes

    Can be used on case class fields and classes in sealed hierarchy to instruct automatically derived GenCodec to use particular name instead of just using parameter or class name.

    Can be used on case class fields and classes in sealed hierarchy to instruct automatically derived GenCodec to use particular name instead of just using parameter or class name.

    For example:

    sealed trait Base
    @name("STH")
    case class Something(@name("dbname") paramname: Int) extends Base
    object Base {
      implicit codec = GenCodec.auto[Base]
    }

    GenCodec.write[Base](someOutput, Something(42)) would write an object {"STH": {"dbname": 42}} instead of {"Something": {"paramname": 42}}.

    NOTE: @name annotation may be defined on any level of inheritance hierarchy. For instance, if a case class field overrides a method of some base trait, the @name annotation may be used on that method and will affect the case class field.

  48. class outOfOrder extends Annotation with StaticAnnotation

    To be used in conjunction with flatten.

    To be used in conjunction with flatten. It can be applied on one or more of case class fields in a sealed hierarchy to instruct the auto-materialized GenCodec that this particular field may appear before _case field in the serialized format during reading.

    @flatten sealed trait Base
    case class FirstCase(@outOfOrder tag: String, int: Int) extends Base
    case class SecondCase(dbl: Double) extends Base
    object Base {
      implicit val codec: GenCodec[Base] = GenCodec.materialize[Base]
    }

    The following JSON (assuming this is the representation used) would correctly deserialize as FirstCase("someTag", 42):

    {"tag": "someTag", "_case": "FirstCase", "int": 42}

    Field annotated with @outOfOrder annotation doesn't have to be present in every case class, but if it is present, all case classes must annotate it and give it exactly the same type. The annotation may also be inherited, e.g.

    @flatten sealed trait Base {
      @outOfOrder def tag: String
    }
    case class FirstCase(tag: String, int: Int) extends Base
    case class SecondCase(tag: String, dbl: Double) extends Base

    The direct motivation for this annotation was the ability to use flatten on MongoDB entities with an _id field. When reading entities from MongoDB, the _id field is always at the beginning of a BSON document and therefore GenCodec must be able to read it before it knows which case class of sealed hierarchy is being deserialized.

  49. class transientDefault extends Annotation with StaticAnnotation

    If some case class field has default value or whenAbsent annotation, you can use transientDefault on this field to instruct an automatically derived GenCodec to not persist the value of that field if it's equal to the default value.

    If some case class field has default value or whenAbsent annotation, you can use transientDefault on this field to instruct an automatically derived GenCodec to not persist the value of that field if it's equal to the default value.

    For example:

    case class Something(str: String, @transientDefault int: Int = 42)
    object Something {
      implicit val codec = GenCodec.auto[Something]
    }

    GenCodec.write(someOutput, Something("lol", 10)) would yield object {"str": "lol", "int": 10} but GenCodec.write(someOutput, Something("lol", 42)) would yield object {"str": "lol"} because the value of int is the same as the default value.

    NOTE: transientDefault also works for method parameters in RPC framework.

  50. class transparent extends Annotation with StaticAnnotation

    Can be used on case classes with exactly one field to instruct automatically generated GenCodec that the class is a "transparent wrapper" and should be serialized to the same representation as the value of its sole field.

  51. class whenAbsent[+T] extends Annotation with StaticAnnotation

    An alternative way to provide default value for case class parameter used during deserialization with GenCodec when its field is missing in data being deserialized.

    An alternative way to provide default value for case class parameter used during deserialization with GenCodec when its field is missing in data being deserialized. Normally, Scala-level default parameter values are picked up, but you may want to use this annotation instead if you don't want to pollute your Scala classes with unintended default parameter values (i.e. you want a default value *only* for deserialization).

    case class HasDefault(@whenAbsent("default") str: String)
    object HasDefault extends HasGenCodec[HasDefault]

    If a parameter has both Scala-level default value and is annotated with @whenAbsent then value from annotation takes priority. You can use this to have different source-level default value and different default value for deserialization. You can also leverage this to "remove" default value for deserialization:

    case class HasNoDefault(@whenAbsent(throw new Exception) str: String = "default")
    object HasDefault extends HasGenCodec[HasDefault]

    NOTE: whenAbsent also works for method parameters in RPC framework.

Ungrouped