简体   繁体   English

同一类型上的类型不匹配

[英]Type mismatch on same type

I am trying to send a json response with spray-routing I am getting this error after invoking on complete 我正在尝试通过喷雾路由发送json响应,在完成时调用此错误

Error:(45, 29) type mismatch;
 found   : _2.Entities.EventsSearchResponse where val _2: eyein.eventful.eventful
 required: _3.Entities.EventsSearchResponse where val _3: eyein.eventful.eventful
                api.jsonize(value)
                            ^

api.jsonize is just a wrapper for marshal api.jsonize只是marshal的包装器

Using it in the orginal api file prints the json as string with no problems. 在原始api文件中使用它可以毫无问题地将json打印为字符串。

I am mostly interested in the the error there is obviously some typing problem but I am not sure where to begin 我最感兴趣的是该错误,显然存在一些打字问题,但我不确定从哪里开始

this is the route 这是路线

val myRoute =
  path("event" / IntNumber / IntNumber) {(from,to) =>
    get {
      respondWithMediaType(`application/json`) {
        onSuccess(api.GetEventsByDate(from.toString,to.toString)){ value =>
            complete{
              api.jsonize(value)
            }
          }
        }
      }
    }

jsonize signature jsonize签名

  def jsonize(eventList : Entities.EventsSearchResponse)

Scala considers the types of inner classes to be path-dependent, and does not always infer path-dependent types the way you'd expect. Scala认为内部类的类型是依赖于路径的,并且并不总是以您期望的方式推断依赖于路径的类型。 Try giving it an explicitly path-dependent type: 尝试给它一个显式依赖路径的类型:

onSuccess(api.GetEventsByDate(...): Future[api.Entities.EventsSearchResponse]) {
  value: api.Entities.EventsSearchResponse => ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM