spray.json (scala): how to (de)serializing nested Option[JsNumber] <p>I am trying to (de)serialize the following code:</p> <pre><code>class EntityId(value: Long) extends MappedTo[Long] { override def toString = value.toString } object EntityId extends DefaultJsonProtocol { implicit object EntityIdJsonFormat extends RootJsonFormat[EntityId] { def write(entityId: EntityId) = JsNumber(entityId.value) def read(value: JsNumber) = value match { case JsNumber(entityIdLong) =&gt; new EntityId(entityIdLong.toLongExact) } } } case class Version(value: Long) extends MappedTo[Long] { def increment() = copy(value + 1) } object Version extends DefaultJsonProtocol { implicit object VersionJsonFormat extends RootJsonFormat[Version] { def write(version: Version) = JsNumber(version.value) def read(value: JsNumber) = value match { case JsNumber(version) =&gt; new Version(version.toLongExact) } } } /** * Trait for entities: all model classes that require an auto-incremental ID and optimistic locking. */ trait Entity[I &lt;: EntityId] { def id: Option[I] def version: Option[Version] def created: Option[Instant] def modified: Option[Instant] def isPersisted = id.isDefined } object Entity extends DefaultJsonProtocol { ??????????????? } </code></pre> <p>(it is based on Blogimistic TypeSafe template).</p> <p>my problems starts with the nested part. Because in Entity the EntityId is optional, I cannot figure how to serialize and deserialize it. how should this be done?</p>