Package org.springframework.test.http
Class HttpMessageContentConverter
java.lang.Object
org.springframework.test.http.HttpMessageContentConverter
Convert HTTP message content for testing purposes.
- Since:
- 6.2
- Author:
- Stephane Nicoll
-
Method Summary
Modifier and TypeMethodDescription<T> T
convert
(HttpInputMessage message, MediaType mediaType, ResolvableType targetType) Convert the givenHttpInputMessage
whose content must match the givenMediaType
to the requestedtargetType
.<T> T
convertViaJson
(Object value, ResolvableType targetType) Convert the given raw value to the giventargetType
by writing it first to JSON and reading it back.static HttpMessageContentConverter
of
(Iterable<HttpMessageConverter<?>> candidates) Create an instance with an iterable of the candidates to use.static HttpMessageContentConverter
of
(HttpMessageConverter<?>... candidates) Create an instance with a vararg of the candidates to use.
-
Method Details
-
of
Create an instance with an iterable of the candidates to use.- Parameters:
candidates
- the candidates
-
of
Create an instance with a vararg of the candidates to use.- Parameters:
candidates
- the candidates
-
convert
public <T> T convert(HttpInputMessage message, MediaType mediaType, ResolvableType targetType) throws IOException, HttpMessageNotReadableException Convert the givenHttpInputMessage
whose content must match the givenMediaType
to the requestedtargetType
.- Type Parameters:
T
- the converted object type- Parameters:
message
- an input messagemediaType
- the media type of the inputtargetType
- the target type- Returns:
- a value of the given
targetType
- Throws:
IOException
HttpMessageNotReadableException
-
convertViaJson
Convert the given raw value to the giventargetType
by writing it first to JSON and reading it back.- Type Parameters:
T
- the converted object type- Parameters:
value
- the value to converttargetType
- the target type- Returns:
- a value of the given
targetType
- Throws:
IOException
-