Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala ContentType字符集为的NodeSeqMarshaller未解析_Scala_Character Encoding_Marshalling_Spray - Fatal编程技术网

Scala ContentType字符集为的NodeSeqMarshaller未解析

Scala ContentType字符集为的NodeSeqMarshaller未解析,scala,character-encoding,marshalling,spray,Scala,Character Encoding,Marshalling,Spray,正在尝试通过邮递员请求获取内容。我的XML封送拆收器似乎让我失望,也就是说,它从未基于Accept标头和字符集解析正确的封送拆收器选项 我有以下资料: object ResponseVO { val NodeSeqMarshaller = Marshaller.delegate[ResponseVO, NodeSeq](ContentType(`text/xml`, `UTF-8`)) { respVO => <ussd><type>{ respVO.re

正在尝试通过邮递员请求获取内容。我的XML封送拆收器似乎让我失望,也就是说,它从未基于Accept标头和字符集解析正确的封送拆收器选项

我有以下资料:

object ResponseVO {  
   val NodeSeqMarshaller = Marshaller.delegate[ResponseVO, NodeSeq](ContentType(`text/xml`, `UTF-8`)) { respVO => <ussd><type>{ respVO.respType }</type><message>{ respVO.message }</message></ussd> }

   val supportedContentTypes = List[ContentType](ContentType(`text/xml`, `UTF-8`))
   implicit val marshaller = Marshaller[ResponseVO] { (respVO, ctx) =>
   ctx.tryAccept(supportedContentTypes) match {
    case Some(ContentType(`text/xml`, `UTF-8`)) => NodeSeqMarshaller(respVO, ctx)
    case whatever                               => println(whatever); ctx.rejectMarshalling(supportedContentTypes);
  }
}
}
不幸的是,我似乎从来没有正确地进行谈判,即我的马歇尔勒决议将把炸弹投入“无论什么”的区块,并以406作为回应

"Resource representation is only available with these Content-Types:
text/xml;字符集=UTF-8“

我使用的是Postman,我的请求标题如下:

GET /ussd?msisdn=0794138690&type=1&network=4&msg=hello&session=99 HTTP/1.1
Host: localhost:9999
Connection: keep-alive
Accept: text/xml; charset=UTF-8
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/40.0.2214.91 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,nl;q=0.6
这可能是一些小而愚蠢的事情——希望有人能帮我指引正确的方向


谢谢

看看案例类
ContentType
是如何定义的:

case class ContentType(mediaType: MediaType, definedCharset: Option[HttpCharset])
请注意,
definedCharset
被定义为一个
选项[HttpCharset]
,因此通过

case Some(ContentType(`text/xml`, `UTF-8`)) => ...
永远不会成功。因此您需要使用
Some
来成功执行模式匹配:

case Some(ContentType(`text/xml`, Some(`UTF-8`))) => ...
case Some(ContentType(`text/xml`, Some(`UTF-8`))) => ...