Skip to content

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

@s5bug

Description

@s5bug
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions