2016-12-04 2 views
1

ich die folgende Fall Klasse haben:konnte nicht implizite Format für Parameter finden

case class Customer(name: String) 

, die wie folgt codiert wird:

class ServiceJsonProtocol extends DefaultJsonProtocol { 
    implicit val customerProtocol = jsonFormat1(Customer) 
} 

Das Problem ist, dass für diesen Code:

val route = 
    path("customer") { 
    post { 
     entity(as[Customer]) { 
     customer => complete { 
      customers.add(customer) 
      s"got customer with name ${customer.name}" 
     } 
     } 
    } 

Ich bekomme das:

could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[Customer] 
[error]   entity(as[Customer]) { 

Was ist das Problem?

+1

Wenn Sie 'spray-json' verwenden, erwähnen Sie es bitte in Ihrer Frage. Werfen Sie auch einen Blick auf http://stackoverflow.com/questions/33574176/akka-http-could-not-find-implicit-value-for-parameter-unmarshalling – YoungSpice

Antwort

4

Sie müssen SprayJsonSupport erweitern. Dies kompiliert:

Ich nehme an, Sie verwenden akka http. Mit Spray sollte dieser Fehler nicht passieren.

Verwandte Themen