use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class ResourceRegionEncoderTests method canEncode.
@Test
public void canEncode() {
ResolvableType resourceRegion = ResolvableType.forClass(ResourceRegion.class);
MimeType allMimeType = MimeType.valueOf("*/*");
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Resource.class), MimeTypeUtils.APPLICATION_OCTET_STREAM));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Resource.class), allMimeType));
assertTrue(this.encoder.canEncode(resourceRegion, MimeTypeUtils.APPLICATION_OCTET_STREAM));
assertTrue(this.encoder.canEncode(resourceRegion, allMimeType));
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class AbstractJackson2Codec method resolveVariable.
private ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
ResolvableType resolvedType;
if (contextType.hasGenerics()) {
resolvedType = ResolvableType.forType(typeVariable, contextType);
if (resolvedType.resolve() != null) {
return resolvedType;
}
}
resolvedType = resolveVariable(typeVariable, contextType.getSuperType());
if (resolvedType.resolve() != null) {
return resolvedType;
}
for (ResolvableType ifc : contextType.getInterfaces()) {
resolvedType = resolveVariable(typeVariable, ifc);
if (resolvedType.resolve() != null) {
return resolvedType;
}
}
return ResolvableType.NONE;
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class FormHttpMessageWriter method write.
@Override
public Mono<Void> write(Publisher<? extends MultiValueMap<String, String>> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType == null) {
contentType = MediaType.APPLICATION_FORM_URLENCODED;
outputMessage.getHeaders().setContentType(contentType);
}
Charset charset = getMediaTypeCharset(contentType);
return Flux.from(inputStream).single().map(form -> generateForm(form, charset)).then(value -> {
ByteBuffer byteBuffer = charset.encode(value);
DataBuffer buffer = outputMessage.bufferFactory().wrap(byteBuffer);
outputMessage.getHeaders().setContentLength(byteBuffer.remaining());
return outputMessage.writeWith(Mono.just(buffer));
});
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodePojoWithError.
@Test
public void decodePojoWithError() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"foo\":}"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null, Collections.emptyMap());
StepVerifier.create(flux).verifyError(CodecException.class);
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodeToFlux.
@Test
public void decodeToFlux() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null, Collections.emptyMap());
StepVerifier.create(flux).expectNext(new Pojo("f1", "b1")).expectNext(new Pojo("f2", "b2")).expectComplete().verify();
}
Aggregations