prop> (a: Array[String]) => | DynamoFormat[Array[String]].read(DynamoFormat[Array[String]].write(a)).right.getOrElse(Array("error")).deep == | a.deep
prop> (b: Boolean) => | DynamoFormat[Boolean].read(DynamoFormat[Boolean].write(b)) == Right(b)
prop> (ab:Array[Byte]) => | DynamoFormat[Array[Byte]].read(DynamoFormat[Array[Byte]].write(ab)) == Right(ab)
prop> (b: Byte) => | DynamoFormat[Byte].read(DynamoFormat[Byte].write(b)) == Right(b)
Returns a DynamoFormat for the case where A
can always be converted B
,
with write
, but read
may throw an exception for some value of B
Returns a DynamoFormat for the case where A
can always be converted B
,
with write
, but read
may throw an exception for some value of B
>>> import org.joda.time._ >>> val jodaStringFormat = DynamoFormat.coercedXmap[LocalDate, String, IllegalArgumentException]( ... LocalDate.parse ... )( ... _.toString ... ) >>> jodaStringFormat.read(jodaStringFormat.write(new LocalDate(2007, 8, 18))) Right(2007-08-18) >>> import com.amazonaws.services.dynamodbv2.model.AttributeValue >>> jodaStringFormat.read(new AttributeValue().withS("Togtogdenoggleplop")) Left(TypeCoercionError(java.lang.IllegalArgumentException: Invalid format: "Togtogdenoggleplop"))
prop> (d: Double) => | DynamoFormat[Double].read(DynamoFormat[Double].write(d)) == Right(d)
prop> import com.amazonaws.services.dynamodbv2.model.AttributeValue prop> (s: Set[Double]) => | val av = new AttributeValue().withNS(s.map(_.toString).toList: _*) | DynamoFormat[Set[Double]].write(s) == av && | DynamoFormat[Set[Double]].read(av) == Right(s)
prop> (i: Int) => | DynamoFormat[Int].read(DynamoFormat[Int].write(i)) == Right(i)
prop> import com.amazonaws.services.dynamodbv2.model.AttributeValue prop> (s: Set[Int]) => | val av = new AttributeValue().withNS(s.map(_.toString).toList: _*) | DynamoFormat[Set[Int]].write(s) == av && | DynamoFormat[Set[Int]].read(av) == Right(s)
Returns a DynamoFormat for the case where A
and B
are isomorphic,
i.e.
Returns a DynamoFormat for the case where A
and B
are isomorphic,
i.e. an A
can always be converted to a B
and vice versa.
If there are some values of B
that have no corresponding value in A
,
use DynamoFormat.xmap or DynamoFormat.coercedXmap.
>>> import com.amazonaws.services.dynamodbv2.model.AttributeValue >>> case class UserId(value: String) >>> implicit val userIdFormat = ... DynamoFormat.iso[UserId, String](UserId.apply)(_.value) >>> DynamoFormat[UserId].read(new AttributeValue().withS("Eric")) Right(UserId(Eric))
prop> (l: List[String]) => | DynamoFormat[List[String]].read(DynamoFormat[List[String]].write(l)) == | Right(l)
prop> (l: Long) => | DynamoFormat[Long].read(DynamoFormat[Long].write(l)) == Right(l)
prop> import com.amazonaws.services.dynamodbv2.model.AttributeValue prop> (s: Set[Long]) => | val av = new AttributeValue().withNS(s.map(_.toString).toList: _*) | DynamoFormat[Set[Long]].write(s) == av && | DynamoFormat[Set[Long]].read(av) == Right(s)
prop> (m: Map[String, Int]) => | DynamoFormat[Map[String, Int]].read(DynamoFormat[Map[String, Int]].write(m)) == | Right(m)
prop> (o: Option[Long]) => | DynamoFormat[Option[Long]].read(DynamoFormat[Option[Long]].write(o)) == | Right(o) >>> DynamoFormat[Option[Long]].read(new com.amazonaws.services.dynamodbv2.model.AttributeValue().withNULL(true)) Right(None)
prop> (sq: Seq[String]) => | DynamoFormat[Seq[String]].read(DynamoFormat[Seq[String]].write(sq)) == | Right(sq)
prop> (s: Short) => | DynamoFormat[Short].read(DynamoFormat[Short].write(s)) == Right(s)
This ensures that if, for instance, you specify an update with Some(5) rather
than making the type of Option
explicit, it doesn't fall back to auto-derivation
prop> (s: String) => | DynamoFormat[String].read(DynamoFormat[String].write(s)) == Right(s)
prop> import com.amazonaws.services.dynamodbv2.model.AttributeValue prop> (s: Set[String]) => | val av = new AttributeValue().withSS(s.toList: _*) | DynamoFormat[Set[String]].write(s) == av && | DynamoFormat[Set[String]].read(av) == Right(s)
prop> implicit val arbitraryUUID = org.scalacheck.Arbitrary(org.scalacheck.Gen.uuid) prop> (uuid: java.util.UUID) => | DynamoFormat[java.util.UUID].read(DynamoFormat[java.util.UUID].write(uuid)) == | Right(uuid)
prop> (v: Vector[String]) => | DynamoFormat[Vector[String]].read(DynamoFormat[Vector[String]].write(v)) == | Right(v)
>>> import org.joda.time._ >>> import com.amazonaws.services.dynamodbv2.model.AttributeValue >>> implicit val jodaLongFormat = DynamoFormat.xmap[DateTime, Long]( ... l => Right(new DateTime(l).withZone(DateTimeZone.UTC)) ... )( ... _.withZone(DateTimeZone.UTC).getMillis ... ) >>> DynamoFormat[DateTime].read(new AttributeValue().withN("0")) Right(1970-01-01T00:00:00.000Z)