PlayQ / d4s

Dynamo DB Database Done Scala-way
Apache License 2.0
29 stars 6 forks source link

Current attribute encoder does not support circe style encodind where we can drop nulls. #274

Closed aliubymov-playq closed 3 years ago

aliubymov-playq commented 3 years ago
  implicit def optionEncoder[T: D4SAttributeEncoder]: D4SAttributeEncoder[Option[T]] = {
    item: Option[T] =>
      item.map(encode[T]).getOrElse(AttributeValue.builder().nul(true).build())
  }

when we need to

  implicit def optionEncoder[T: D4SAttributeEncoder]: D4SAttributeEncoder[Option[T]] = {
    item: Option[T] =>
      item.map(encode[T]) // expects Optional attribute to not write unnecessary parts
  }

Decoder already supports optional attributes.