Package play.mvc
Class Http.RequestBody
java.lang.Object
play.mvc.Http.RequestBody
- Enclosing class:
- Http
The request body.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TCast this RequestBody as T if possible.asBytes()The request content as a ByteString.The request content parsed as URL form-encoded.com.fasterxml.jackson.databind.JsonNodeasJson()<A> Http.MultipartFormData<A>The request content parsed as multipart form data.asRaw()asText()asXml()<A> Optional<A>Converts a JSON request to a given class.toString()
-
Constructor Details
-
RequestBody
-
-
Method Details
-
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
The request content parsed as URL form-encoded.- Returns:
- the request content parsed as URL form-encoded.
-
asRaw
- Returns:
- The request content as Array bytes.
-
asText
- Returns:
- The request content as text.
-
asXml
- Returns:
- The request content as XML.
-
asJson
public com.fasterxml.jackson.databind.JsonNode asJson()- Returns:
- The request content as Json.
-
parseJson
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
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
Cast this RequestBody as T if possible.- Type Parameters:
T- type of the providedtType- Parameters:
tType- class that we are trying to cast the body as- Returns:
- either a successful cast into T or null
-
toString
-