Giter Club home page Giter Club logo

Comments (5)

philwills avatar philwills commented on May 27, 2024

I think that if you have a custom DynamoFormat for Option in scope, that should be able to override the default behaviour to deal with this case. e.g.

import com.gu.scanamo._
import cats.data.Xor
import com.amazonaws.services.dynamodbv2.model.AttributeValue
import com.gu.scanamo.error.DynamoReadError

implicit def nullOptionFormat[T](implicit f: DynamoFormat[T]) = new DynamoFormat[Option[T]]{
  def read(av: AttributeValue): Xor[DynamoReadError, Option[T]] = {
    Option(av).filter(!_.isNULL).map(f.read(_).map(Some(_)))
       .getOrElse(Xor.right(Option.empty[T]))
  }
  def write(t: Option[T]): AttributeValue = t.map(f.write).getOrElse(new AttributeValue().withNULL(true))
}

then

scala>DynamoFormat[Option[String]].write(Option.empty[String])
res0: com.amazonaws.services.dynamodbv2.model.AttributeValue = {NULL: true,}

Does that deal adequately with your case?

from scanamo.

philwills avatar philwills commented on May 27, 2024

There's also probably a case for adding that filter on read to the default, but I don't particularly like the idea of things not being symmetric by default.

from scanamo.

travisbrown avatar travisbrown commented on May 27, 2024

@philwills You could add that behavior to the read side (to accommodate other systems that use explicit NULL) but leave write the same. Still not symmetric, but it's a less dramatic change.

from scanamo.

cb372 avatar cb372 commented on May 27, 2024

For the record, I had the same problem when upgrading from an ancient version of Scanamo (serves me right for being an early adopter). Pre-0.3, Scanamo used to encode None as an explicit NULL.

Here is the change.

from scanamo.

philwills avatar philwills commented on May 27, 2024

Closed by #65

from scanamo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.