I'm implementing some rest API that use spray and akka The API should expose some kind of user CRUD. I'll use only create user in this question...
case class User(id:String, name:String)
case class Register(user:User, registrationId:String)
trait DefaultJsonFormats extends DefaultJsonProtocol with SprayJsonSupport with MetaMarshallers {}
class RegistrationService(registration: ActorRef)
(implicit executionContext: ExecutionContext)
extends Directives with DefaultJsonFormats {
implicit val timeout = Timeout(2.seconds)
implicit val userFormat = jsonFormat3(User)
implicit val registerFormat = jsonFormat1(Register)
implicit val registeredFormat = jsonFormat1(Registered)
val route =
path("register") {
post { handleWith { ru: Register => (registration ? ru).mapTo[Registered] } }
}
Now Lets suppose that User class has 30 fields but there is no jsonFormat30(...) How can I use such implicits for any case class object?