Search in sources :

Example 16 with ResolvableType

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;
}
Also used : ResolvableType(org.springframework.core.ResolvableType)

Example 17 with ResolvableType

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();
}
Also used : Pojo(org.springframework.http.codec.Pojo) ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Example 18 with ResolvableType

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();
}
Also used : Pojo(org.springframework.http.codec.Pojo) ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Example 19 with ResolvableType

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();
}
Also used : ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Example 20 with ResolvableType

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();
}
Also used : ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Aggregations

ResolvableType (org.springframework.core.ResolvableType)96 Test (org.junit.Test)66 MethodParameter (org.springframework.core.MethodParameter)20 DataBuffer (org.springframework.core.io.buffer.DataBuffer)15 ServerWebExchange (org.springframework.web.server.ServerWebExchange)14 List (java.util.List)11 MediaType (org.springframework.http.MediaType)10 Flux (reactor.core.publisher.Flux)10 Mono (reactor.core.publisher.Mono)10 Map (java.util.Map)9 Assert (org.springframework.util.Assert)7 Collections (java.util.Collections)6 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)6 ArrayList (java.util.ArrayList)5 ReactiveAdapter (org.springframework.core.ReactiveAdapter)5 Pojo (org.springframework.http.codec.Pojo)5 ServerWebInputException (org.springframework.web.server.ServerWebInputException)5 Publisher (org.reactivestreams.Publisher)4 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)4 Single (rx.Single)4