How to apply toJson to case instance using spray-json library

Registration.scala

package model

import akka.actor.Actor
import spray.json._
import DefaultJsonProtocol._

case class Registration(
  system: String, 
  identity: String)

object RegistrationProtocol extends DefaultJsonProtocol {
  implicit val adsRegistrationFormat = jsonFormat2(Registration)
}

      

RegistrationService.scala

import akka.actor.{Props, ActorLogging, Actor}
import model.Registration

object RegistrationsService {
  case class PostRegistrationMessage(registration: Registration)

  def props(property: String) = Props(classOf[RegistrationsService], property)
}

class RegistrationsService(property: String) extends Actor with ActorLogging {
  import RegistrationsService._

  def receive = {
    case PostRegistrationMessage(registration) => {
      import model.RegistrationProtocol._

      val json = registration.toJson

    }
  }
}

      

Can someone help me understand why this is happening with a compilation error? The toJson value is not a member of model.Registration and how to fix it. This is if the last line of the above code is missing " val json = registration.toJson "

+3


source to share


1 answer


You need to import the implicit operations provided by the spray into RegistrationService.scala too



  import model.RegistrationProtocol._
  import spray.json._

      

+4


source







All Articles