Java Code Examples for org.springframework.core.ParameterizedTypeReference#getType()

The following examples show how to use org.springframework.core.ParameterizedTypeReference#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpMessageConverterExtractorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void generics() throws IOException {
	GenericHttpMessageConverter<String> converter = mock(GenericHttpMessageConverter.class);
	List<HttpMessageConverter<?>> converters = createConverterList(converter);
	HttpHeaders responseHeaders = new HttpHeaders();
	MediaType contentType = MediaType.TEXT_PLAIN;
	responseHeaders.setContentType(contentType);
	String expected = "Foo";
	ParameterizedTypeReference<List<String>> reference = new ParameterizedTypeReference<List<String>>() {};
	Type type = reference.getType();
	extractor = new HttpMessageConverterExtractor<List<String>>(type, converters);
	given(response.getStatusCode()).willReturn(HttpStatus.OK);
	given(response.getHeaders()).willReturn(responseHeaders);
	given(response.getBody()).willReturn(new ByteArrayInputStream(expected.getBytes()));
	given(converter.canRead(type, null, contentType)).willReturn(true);
	given(converter.read(eq(type), eq(null), any(HttpInputMessage.class))).willReturn(expected);

	Object result = extractor.extractData(response);

	assertEquals(expected, result);
}
 
Example 2
Source File: HttpMessageConverterExtractorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void generics() throws IOException {
	GenericHttpMessageConverter<String> converter = mock(GenericHttpMessageConverter.class);
	HttpHeaders responseHeaders = new HttpHeaders();
	MediaType contentType = MediaType.TEXT_PLAIN;
	responseHeaders.setContentType(contentType);
	String expected = "Foo";
	ParameterizedTypeReference<List<String>> reference = new ParameterizedTypeReference<List<String>>() {};
	Type type = reference.getType();
	extractor = new HttpMessageConverterExtractor<List<String>>(type, createConverterList(converter));
	given(response.getRawStatusCode()).willReturn(HttpStatus.OK.value());
	given(response.getHeaders()).willReturn(responseHeaders);
	given(response.getBody()).willReturn(new ByteArrayInputStream(expected.getBytes()));
	given(converter.canRead(type, null, contentType)).willReturn(true);
	given(converter.read(eq(type), eq(null), any(HttpInputMessage.class))).willReturn(expected);

	Object result = extractor.extractData(response);
	assertEquals(expected, result);
}
 
Example 3
Source File: AsyncRestTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method,
		@Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
		throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor);
}
 
Example 4
Source File: AsyncRestTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor);
}
 
Example 5
Source File: AsyncRestTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method,
		@Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
		throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor);
}
 
Example 6
Source File: AsyncRestTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
		@Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType,
		Map<String, ?> uriVariables) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 7
Source File: AsyncRestTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
		@Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType,
		Object... uriVariables) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 8
Source File: RestTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
		throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return nonNull(doExecute(requestEntity.getUrl(), requestEntity.getMethod(), requestCallback, responseExtractor));
}
 
Example 9
Source File: RestTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType) throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return nonNull(execute(url, method, requestCallback, responseExtractor));
}
 
Example 10
Source File: RestTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 11
Source File: AsyncRestTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 12
Source File: RestTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType) throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor);
}
 
Example 13
Source File: AsyncRestTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
		@Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType,
		Map<String, ?> uriVariables) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 14
Source File: AsyncRestTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 15
Source File: RestTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 16
Source File: AsyncRestTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {

	Type type = responseType.getType();
	AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 17
Source File: RestTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return nonNull(execute(url, method, requestCallback, responseExtractor, uriVariables));
}
 
Example 18
Source File: RestTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
		ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {

	Type type = responseType.getType();
	RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
	return execute(url, method, requestCallback, responseExtractor, uriVariables);
}
 
Example 19
Source File: DefaultServerRequestBuilder.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public <T> T body(ParameterizedTypeReference<T> bodyType) throws IOException, ServletException {
	Type type = bodyType.getType();
	return bodyInternal(type, DefaultServerRequest.bodyClass(type));
}
 
Example 20
Source File: DefaultServerRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public <T> T body(ParameterizedTypeReference<T> bodyType) throws IOException, ServletException {
	Type type = bodyType.getType();
	return bodyInternal(type, bodyClass(type));
}