Skip to content

Commit 80fa8cf

Browse files
committed
fix breaking change in MediaType.toString
1 parent 869b16c commit 80fa8cf

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

core/src/main/scala/sttp/model/MediaType.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ case class MediaType(
6363

6464
def isModel: Boolean = mainType.equalsIgnoreCase("model")
6565

66-
override lazy val toString: String = {
66+
private lazy val toStringCache: String = {
6767
val sb = new java.lang.StringBuilder(32) // "application/json; charset=utf-8".length == 31 ;)
6868
sb.append(mainType).append('/').append(subType)
6969
charset match {
@@ -77,6 +77,7 @@ case class MediaType(
7777
sb.toString
7878
}
7979

80+
override def toString() = toStringCache
8081
override lazy val hashCode: Int = toString.toLowerCase.hashCode
8182

8283
override def equals(that: Any): Boolean =

core/src/test/scala/sttp/model/MediaTypeTests.scala

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ class MediaTypeTests extends AnyFlatSpec with Matchers with TableDrivenPropertyC
5959
an[IllegalArgumentException] shouldBe thrownBy(MediaType.unsafeApply("te=xt", "plain"))
6060
}
6161

62+
it should "have a regular toString" in {
63+
val mt = MediaType.ApplicationGzip
64+
mt.toString shouldBe "application/gzip"
65+
mt.toString() shouldBe "application/gzip"
66+
}
67+
6268
private val matchCases = Table(
6369
("media type", "content type range", "matches"),
6470
// simple matching

0 commit comments

Comments
 (0)