Closed s5bug closed 5 years ago
@sorenbug I will need to see your exact code, but my guess is that this is going on - You try to convert to string first and then trying to json. Default implementation of encoders/decoders is fairly strict, so if you read text, mime must be text and not json.
To fix this, you shall write simple decoder, which will be in your case a very simple one-two liner. You will use your serialization instance implicit( I think you mentioned you using circe) and essentially create and implciti saying `always when I have circe available for the type, I also have deserializer in fs2http, that requires application/json type and de/serializes the content).
From the examples in tests and current implementation of the decoder it shall be straightforward implementation in your case.
Should I take a look at fs2-http-circe?
@sorenbug from the first look I had on fs2-http-circe, yes, this is what you need to do.
I ended up (since it was only visible to one method) just making an unbounded String decoder.
implicit val sd: BodyDecoder[String] = (bytes: ByteVector, contentType: ContentType) => {
MIMECharset.asJavaCharset(util.getCharset(contentType).getOrElse(MIMECharset.`UTF-8`)).flatMap { implicit chs =>
Attempt.fromEither(
bytes.decodeString.left
.map(ex => Err(s"Failed to decode string ContentType: $contentType, charset: $chs, err: ${ex.getMessage}"))
)
}
}
RequestUtil.scala:64