Akka เส้นทาง TestKit ไม่สามารถ unmarshall การตอบสนเป็นข้อความ

0

คำถาม

ฉันมีข้อทดสอบ:

 "fail if date is wrongly formatted" in {
    val endpoint = s"/api/prof?date=wrongdate"
    Get(endpoint) ~> check {
      status shouldBe StatusCodes.BadRequest
      val resp = responseAs[String]
      resp shouldBe "could not be parsed"
    }
 }

อย่างไรก็ตามการทดสอบความผิดพลาดกับต่อไปนี้:

Could not unmarshal response to type 'java.lang.String' for `responseAs` assertion: akka.http.scaladsl.unmarshalling.Unmarshaller$UnsupportedContentTypeException: Unsupported Content-Type [Some(text/plain; charset=UTF-8)], supported: application/json

Response was: HttpResponse(400 Bad Request,List(),HttpEntity.Strict(text/plain; charset=UTF-8,106 bytes total),HttpProtocol(HTTP/1.1))

ทำไมฉันถึงการตอบสนองศพเป็นข้อความ?

akka akka-http scala scala-2.12
2021-11-23 15:46:11
1

คำตอบที่ดีที่สุด

1

คุณสันนิษฐานได้เลยว่าเค้าต้องการที่แยกกำหนด unmarshaller สำหรับ LANGUAGE อยู่ในขอบเขตนั้นถูกเลือที่ unmarshaller ในสมควรเจอแบบนั้นด้วย

เพิ่มบางอย่างอย่าง

implicit val responseBodyUnmarshaller =
  Unmarshaller.strict[HttpResponse, HttpEntity](_.entity)
    .andThen(Unmarshaller.stringUnmarshaller)

ควรที่อยู่ของเรื่องนี้

2021-11-23 17:52:23

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................