aboutsummaryrefslogtreecommitdiff
path: root/circe
diff options
context:
space:
mode:
authorBjørn Madsen <bm@aeons.dk>2017-08-09 22:17:53 +0200
committerBjørn Madsen <bm@aeons.dk>2017-08-09 22:17:53 +0200
commit85f93f2ccd282cdfceda8ae76cdf3cbb36d20883 (patch)
treef656e434375c0515051f30eab6f09406d1c759b5 /circe
parent18db8e9d1ee240d11b558cdb9b5c850c5b063080 (diff)
downloadsttp-85f93f2ccd282cdfceda8ae76cdf3cbb36d20883.tar.gz
sttp-85f93f2ccd282cdfceda8ae76cdf3cbb36d20883.tar.bz2
sttp-85f93f2ccd282cdfceda8ae76cdf3cbb36d20883.zip
Move default content type to BasicRequestBody
Revert BodySerializer to be a function, and remove SerializableBody
Diffstat (limited to 'circe')
-rw-r--r--circe/src/main/scala/com/softwaremill/sttp/circe.scala11
-rw-r--r--circe/src/test/scala/com/softwaremill/sttp/CirceTests.scala20
2 files changed, 10 insertions, 21 deletions
diff --git a/circe/src/main/scala/com/softwaremill/sttp/circe.scala b/circe/src/main/scala/com/softwaremill/sttp/circe.scala
index f273e42..95a72e1 100644
--- a/circe/src/main/scala/com/softwaremill/sttp/circe.scala
+++ b/circe/src/main/scala/com/softwaremill/sttp/circe.scala
@@ -1,18 +1,15 @@
package com.softwaremill.sttp
-import com.softwaremill.sttp.model.{ResponseAs, StringBody}
+import com.softwaremill.sttp.model._
import io.circe.parser._
import io.circe.{Decoder, Encoder}
-import scala.language.higherKinds
-
package object circe {
private[sttp] val ApplicationJsonContentType = "application/json"
- implicit def circeBodySerializer[B: Encoder]: BodySerializer[B] =
- BodySerializer.instance(
- body => StringBody(Encoder[B].apply(body).noSpaces, Utf8),
- ApplicationJsonContentType)
+ implicit def circeBodySerializer[B](
+ implicit encoder: Encoder[B]): BodySerializer[B] =
+ b => StringBody(encoder(b).noSpaces, Utf8, Some(ApplicationJsonContentType))
def asJson[B: Decoder]: ResponseAs[Either[io.circe.Error, B], Nothing] =
asString(Utf8).map(decode[B])
diff --git a/circe/src/test/scala/com/softwaremill/sttp/CirceTests.scala b/circe/src/test/scala/com/softwaremill/sttp/CirceTests.scala
index 81b90e6..19a317e 100644
--- a/circe/src/test/scala/com/softwaremill/sttp/CirceTests.scala
+++ b/circe/src/test/scala/com/softwaremill/sttp/CirceTests.scala
@@ -35,7 +35,7 @@ class CirceTests extends FlatSpec with Matchers with EitherValues {
runJsonResponseAs(responseAs)(body).left.value shouldBe an[io.circe.Error]
}
- it should "should encode and decode back to the same thing" in {
+ it should "encode and decode back to the same thing" in {
val outer = Outer(Inner(42, true, "horses"), "cats")
val encoded = extractBody(sttp.body(outer))
@@ -50,7 +50,7 @@ class CirceTests extends FlatSpec with Matchers with EitherValues {
val ct = req.headers.toMap.get("Content-Type")
- ct shouldBe Some("application/json")
+ ct shouldBe Some(contentTypeWithEncoding(ApplicationJsonContentType, Utf8))
}
it should "only set the content type if it was not set earlier" in {
@@ -82,18 +82,10 @@ class CirceTests extends FlatSpec with Matchers with EitherValues {
def extractBody[A[_], B, C](request: RequestT[A, B, C]): String =
request.body match {
- case SerializableBody(serializer, body) =>
- serializer(body) match {
- case StringBody(body, "utf-8") =>
- body
- case StringBody(_, encoding) =>
- fail(
- s"Request body serializes to StringBody with wrong encoding: $encoding")
- case _ =>
- fail("Request body does not serialize to StringBody")
- }
- case _ =>
- fail("Request body is not SerializableBody")
+ case StringBody(body, "utf-8", Some(ApplicationJsonContentType)) =>
+ body
+ case wrongBody =>
+ fail(s"Request body does not serialize to correct StringBody: $wrongBody")
}
def runJsonResponseAs[A](responseAs: ResponseAs[A, Nothing]): String => A =