use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class AbstractJackson2HttpMessageConverter 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;
}
}
ResolvableType superType = contextType.getSuperType();
if (superType != ResolvableType.NONE) {
resolvedType = resolveVariable(typeVariable, superType);
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 Jackson2JsonDecoderTests method decodeToList.
@Test
public void decodeToList() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class);
Mono<Object> mono = new Jackson2JsonDecoder().decodeToMono(source, elementType, null, Collections.emptyMap());
StepVerifier.create(mono).expectNext(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))).expectComplete().verify();
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodePojo.
@Test
public void decodePojo() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null, Collections.emptyMap());
StepVerifier.create(flux).expectNext(new Pojo("foofoo", "barbar")).expectComplete().verify();
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodeEmptyBodyToMono.
@Test
public void decodeEmptyBodyToMono() throws Exception {
Flux<DataBuffer> source = Flux.empty();
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Mono<Object> mono = new Jackson2JsonDecoder().decodeToMono(source, elementType, null, Collections.emptyMap());
StepVerifier.create(mono).expectNextCount(0).expectComplete().verify();
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class Jackson2JsonEncoderTests method encodeWithType.
@Test
public void encodeWithType() throws Exception {
Flux<ParentClass> source = Flux.just(new Foo(), new Bar());
ResolvableType type = ResolvableType.forClass(ParentClass.class);
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, null, Collections.emptyMap());
StepVerifier.create(output).consumeNextWith(stringConsumer("[{\"type\":\"foo\"},{\"type\":\"bar\"}]")).expectComplete().verify();
}
Aggregations