Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializers defined as extends Serializer[T] do not work properly for Option[T] #5

Open
s5bug opened this issue Mar 24, 2018 · 0 comments

Comments

@s5bug
Copy link

s5bug commented Mar 24, 2018

object TimestampSerializer extends Serializer[Instant] {

  val sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ")

  val instantClazz: Class[Instant] = classOf[Instant]

  override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), Instant] = {
    case (TypeInfo(`instantClazz`, _), json) => json match {
      case JString(s) => sdf.parse(s.replaceAll("""\+(\d\d)(?::(\d\d))""", "+$1$2")).toInstant
      case x => throw new MappingException("Can't convert " + x + " to Instant")
    }
  }

  override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
    case x: Instant => JString(x.toString)
  }

}

This is said serializer. The case class that uses an Option[Instant] is needed. The JValue is JNull. Instead of being None it throws an exception.

This is fixed by adding a case JNull => null, but it was not like this before ng.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant