diff --git a/docs/src/test/java/docs/http/javadsl/CustomMediaTypesExampleTest.java b/docs/src/test/java/docs/http/javadsl/CustomMediaTypesExampleTest.java index 3bc6dc1c7..2c16bc922 100644 --- a/docs/src/test/java/docs/http/javadsl/CustomMediaTypesExampleTest.java +++ b/docs/src/test/java/docs/http/javadsl/CustomMediaTypesExampleTest.java @@ -70,7 +70,7 @@ public void customMediaTypes() throws ExecutionException, InterruptedException { extractRequest( req -> complete( - req.entity().getContentType().toString() + req.entity().getContentType().value() + " = " + req.entity().getContentType().getClass())); diff --git a/http-core/src/main/mima-filters/1.2.x.backwards.excludes/content-media-type-value-string.backwards.excludes b/http-core/src/main/mima-filters/1.2.x.backwards.excludes/content-media-type-value-string.backwards.excludes new file mode 100644 index 000000000..1ef1b48c1 --- /dev/null +++ b/http-core/src/main/mima-filters/1.2.x.backwards.excludes/content-media-type-value-string.backwards.excludes @@ -0,0 +1,2 @@ +ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.http.javadsl.model.ContentType.value") +ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.http.javadsl.model.MediaType.value") diff --git a/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/ContentType.scala b/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/ContentType.scala index 5ee185858..3ec0d44be 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/ContentType.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/ContentType.scala @@ -13,6 +13,8 @@ package org.apache.pekko.http.javadsl.model +import org.apache.pekko.annotation.DoNotInherit + import java.util.Optional // Has to be defined in Scala even though it's JavaDSL because of: @@ -45,6 +47,7 @@ object ContentType { * * See [[ContentTypes]] for convenience access to often used values. */ +@DoNotInherit trait ContentType { /** @@ -61,4 +64,10 @@ trait ContentType { * Returns the charset if this ContentType is non-binary. */ def getCharsetOption: Optional[HttpCharset] + + /** + * Returns the string representation of this ContentType + * @since 1.2.0 + */ + def value: String } diff --git a/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/MediaType.scala b/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/MediaType.scala index 89cd99dd1..a3cdf167f 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/MediaType.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/javadsl/model/MediaType.scala @@ -13,6 +13,8 @@ package org.apache.pekko.http.javadsl.model +import org.apache.pekko.annotation.DoNotInherit + /** * Represents an Http media-type. A media-type consists of a main-type and a sub-type. * @@ -65,6 +67,7 @@ object MediaType { } } +@DoNotInherit trait MediaType { /** @@ -110,4 +113,10 @@ trait MediaType { * Creates a media-range from this media-type with a given qValue. */ def toRange(qValue: Float): MediaRange + + /** + * Returns the string representation of this MediaType + * @since 1.2.0 + */ + def value: String }