Packages

trait DynamoFormat[T] extends Serializable

Type class for defining serialisation to and from DynamoDB's AttributeValue

>>> val listOptionFormat = DynamoFormat[List[Option[Int]]]
>>> listOptionFormat.read(listOptionFormat.write(List(Some(1), None, Some(3))))
Right(List(Some(1), None, Some(3)))

Also supports automatic derivation for case classes

>>> case class Farm(animals: List[String])
>>> case class Farmer(name: String, age: Long, farm: Farm)
>>> val farmerF = DynamoFormat[Farmer]
>>> farmerF.read(farmerF.write(Farmer("McDonald", 156L, Farm(List("sheep", "cow")))))
Right(Farmer(McDonald,156,Farm(List(sheep, cow))))

and for sealed trait + case object hierarchies

>>> sealed trait Animal
>>> case object Aardvark extends Animal
>>> case object Zebra extends Animal
>>> case class Pet(name: String, animal: Animal)
>>> val petF = DynamoFormat[Pet]
>>> petF.read(petF.write(Pet("Amy", Aardvark)))
Right(Pet(Amy,Aardvark))

>>> petF.read(petF.write(Pet("Zebediah", Zebra)))
Right(Pet(Zebediah,Zebra))

Problems reading a value are detailed

>>> import cats.syntax.either._

>>> case class Developer(name: String, age: String, problems: Int)
>>> val invalid = DynamoFormat[Farmer].read(DynamoFormat[Developer].write(Developer("Alice", "none of your business", 99)))
>>> invalid
Left(InvalidPropertiesError(NonEmptyList(PropertyReadError(age,NoPropertyOfType(N,{S: none of your business,})), PropertyReadError(farm,MissingProperty))))

>>> invalid.leftMap(cats.Show[error.DynamoReadError].show)
Left('age': not of type: 'N' was '{S: none of your business,}', 'farm': missing)

Optional properties are defaulted to None

>>> case class LargelyOptional(a: Option[String], b: Option[String])
>>> DynamoFormat[LargelyOptional].read(DynamoFormat[Map[String, String]].write(Map("b" -> "X")))
Right(LargelyOptional(None,Some(X)))

Custom formats can often be most easily defined using DynamoFormat.coercedXmap, DynamoFormat.xmap or DynamoFormat.iso

Linear Supertypes
Serializable, Serializable, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DynamoFormat
  2. Serializable
  3. Serializable
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getClass(): Class[_]
    Definition Classes
    Any
  2. abstract def read(av: AttributeValue): Either[DynamoReadError, T]
  3. abstract def write(t: T): AttributeValue

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def default: Option[T]
  6. def equals(arg0: Any): Boolean
    Definition Classes
    Any
  7. def hashCode(): Int
    Definition Classes
    Any
  8. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  9. def toString(): String
    Definition Classes
    Any

Inherited from Serializable

Inherited from Serializable

Inherited from Any

Ungrouped