Search in sources :

Example 41 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class MessageMethodArgumentResolver method getPayloadType.

private Class<?> getPayloadType(MethodParameter parameter) {
    Type genericParamType = parameter.getGenericParameterType();
    ResolvableType resolvableType = ResolvableType.forType(genericParamType).as(Message.class);
    return resolvableType.getGeneric(0).resolve(Object.class);
}
Also used : Type(java.lang.reflect.Type) ResolvableType(org.springframework.core.ResolvableType) ResolvableType(org.springframework.core.ResolvableType)

Example 42 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class GenericApplicationListenerAdapterTests method supportsEventTypeWithSmartApplicationListener.

@Test
public void supportsEventTypeWithSmartApplicationListener() {
    SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
    GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
    ResolvableType type = ResolvableType.forClass(ApplicationEvent.class);
    listener.supportsEventType(type);
    verify(smartListener, times(1)).supportsEventType(ApplicationEvent.class);
}
Also used : ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 43 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class GenericApplicationListenerAdapterTests method genericListenerWildcardTypeTypeErasure.

// Demonstrates we cant inject that event because the listener has a wildcard
@Test
public void genericListenerWildcardTypeTypeErasure() {
    GenericTestEvent<String> stringEvent = createGenericTestEvent("test");
    ResolvableType eventType = ResolvableType.forType(stringEvent.getClass());
    supportsEventType(true, GenericEventListener.class, eventType);
}
Also used : ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 44 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeAndResolvableType.

// But it works if we specify the type properly
@Test
public void genericListenerStrictTypeAndResolvableType() {
    ResolvableType eventType = ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class);
    supportsEventType(true, StringEventListener.class, eventType);
}
Also used : ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.Test)

Example 45 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeNotMatchTypeErasure.

@Test
public void genericListenerStrictTypeNotMatchTypeErasure() {
    GenericTestEvent<Long> longEvent = createGenericTestEvent(123L);
    ResolvableType eventType = ResolvableType.forType(longEvent.getClass());
    supportsEventType(false, StringEventListener.class, eventType);
}
Also used : ResolvableType(org.springframework.core.ResolvableType) 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