Package play.mvc

Class Http.RequestBody

  • Enclosing class:
    Http

    public static final class Http.RequestBody
    extends Object
    The request body.
    • Constructor Detail

      • RequestBody

        public RequestBody​(Object body)
    • Method Detail

      • asMultipartFormData

        public <A> Http.MultipartFormData<A> asMultipartFormData()
        The request content parsed as multipart form data.
        Type Parameters:
        A - the file type (e.g. play.api.libs.Files.TemporaryFile)
        Returns:
        the content parsed as multipart form data
      • asFormUrlEncoded

        public Map<String,​String[]> asFormUrlEncoded()
        The request content parsed as URL form-encoded.
        Returns:
        the request content parsed as URL form-encoded.
      • asRaw

        public Http.RawBuffer asRaw()
        Returns:
        The request content as Array bytes.
      • asText

        public String asText()
        Returns:
        The request content as text.
      • asXml

        public Document asXml()
        Returns:
        The request content as XML.
      • asJson

        public com.fasterxml.jackson.databind.JsonNode asJson()
        Returns:
        The request content as Json.
      • parseJson

        public <A> Optional<A> parseJson​(Class<A> clazz)
        Converts a JSON request to a given class. Conversion is performed with [[Json.fromJson(JsonNode,Class)]].

        Will return Optional.empty() if the request body is not an instance of JsonNode. If the JsonNode simply has missing fields, a valid reference with null fields is return.

        Type Parameters:
        A - The type to convert the JSON value to.
        Parameters:
        clazz - The class to convert the JSON value to.
        Returns:
        The converted value if the request has a JSON body or an empty value if the request has an empty body or a body of a different type.
      • asBytes

        public ByteString asBytes()
        The request content as a ByteString.

        This makes a best effort attempt to convert the parsed body to a ByteString, if it knows how. This includes String, json, XML and form bodies. It doesn't include multipart/form-data or raw bodies that don't fit in the configured max memory buffer, nor does it include custom output types from custom body parsers.

        Returns:
        the request content as a ByteString
      • as

        public <T> T as​(Class<T> tType)
        Cast this RequestBody as T if possible.
        Type Parameters:
        T - type of the provided tType
        Parameters:
        tType - class that we are trying to cast the body as
        Returns:
        either a successful cast into T or null