Java Code Examples for org.springframework.core.ResolvableType#forClassWithGenerics()

The following examples show how to use org.springframework.core.ResolvableType#forClassWithGenerics() . 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: ReactiveTypeHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void writeServerSentEventsWithBuilder() throws Exception {

	ResolvableType type = ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class);

	EmitterProcessor<ServerSentEvent<?>> processor = EmitterProcessor.create();
	SseEmitter sseEmitter = (SseEmitter) handleValue(processor, Flux.class, type);

	EmitterHandler emitterHandler = new EmitterHandler();
	sseEmitter.initialize(emitterHandler);

	processor.onNext(ServerSentEvent.builder("foo").id("1").build());
	processor.onNext(ServerSentEvent.builder("bar").id("2").build());
	processor.onNext(ServerSentEvent.builder("baz").id("3").build());
	processor.onComplete();

	assertEquals("id:1\ndata:foo\n\nid:2\ndata:bar\n\nid:3\ndata:baz\n\n",
			emitterHandler.getValuesAsText());
}
 
Example 2
Source File: IndexedElementsBinder.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
private void bindValue(Bindable<?> target, Collection<Object> collection,
                       ResolvableType aggregateType, ResolvableType elementType, Object value) {
    if (value instanceof String && !StringUtils.hasText((String) value)) {
        return;
    }
    Object aggregate = convert(value, aggregateType, target.getAnnotations());
    ResolvableType collectionType = ResolvableType
            .forClassWithGenerics(collection.getClass(), elementType);
    Collection<Object> elements = convert(aggregate, collectionType);
    collection.addAll(elements);
}
 
Example 3
Source File: Jackson2SmileDecoderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void decodeToMono() {
	List<Pojo> expected = Arrays.asList(pojo1, pojo2);

	Flux<DataBuffer> input = Flux.just(expected)
			.map(this::writeObject)
			.flatMap(this::dataBuffer);

	ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class);
	testDecodeToMono(input, elementType, step -> step
			.expectNext(expected)
			.expectComplete()
			.verify(), null, null);
}
 
Example 4
Source File: FunctionType.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private ResolvableType output(Class<?> type) {
	ResolvableType generic;
	ResolvableType raw = ResolvableType.forClass(type);
	if (isMessage()) {
		raw = ResolvableType.forClassWithGenerics(Message.class, raw);
	}
	if (FunctionType.isWrapper(getOutputWrapper())) {
		generic = ResolvableType.forClassWithGenerics(getOutputWrapper(), raw);
	}
	else {
		generic = raw;
	}
	return generic;
}
 
Example 5
Source File: ApplicationListenerMethodAdapterTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), this.entity.getClass());
}
 
Example 6
Source File: PayloadApplicationEvent.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getPayload()));
}
 
Example 7
Source File: AbstractApplicationEventListenerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public SmartGenericTestEvent(Object source, T payload) {
	super(source, payload);
	this.resolvableType = ResolvableType.forClassWithGenerics(
			getClass(), payload.getClass());
}
 
Example 8
Source File: GenericEventListenerBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
    return ResolvableType.forClassWithGenerics(getClass(),
            ResolvableType.forInstance(getSource()));
}
 
Example 9
Source File: ApplicationListenerMethodAdapterTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), this.entity.getClass());
}
 
Example 10
Source File: PayloadApplicationEvent.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getPayload()));
}
 
Example 11
Source File: OutboundPluginChannelMessageEvent.java    From Cleanstone with MIT License 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
    return ResolvableType.forClassWithGenerics(getClass(),
            ResolvableType.forInstance(message));
}
 
Example 12
Source File: OutboundPacketEvent.java    From Cleanstone with MIT License 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
    return ResolvableType.forClassWithGenerics(getClass(),
            ResolvableType.forInstance(packet));
}
 
Example 13
Source File: ResolvableMethod.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static ResolvableType toResolvableType(Class<?> type, Class<?>... generics) {
	return (ObjectUtils.isEmpty(generics) ? ResolvableType.forClass(type) :
			ResolvableType.forClassWithGenerics(type, generics));
}
 
Example 14
Source File: ResolvableMethod.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static ResolvableType toResolvableType(Class<?> type, Class<?>... generics) {
	return (ObjectUtils.isEmpty(generics) ? ResolvableType.forClass(type) :
			ResolvableType.forClassWithGenerics(type, generics));
}
 
Example 15
Source File: PayloadApplicationEvent.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public ResolvableType getResolvableType() {
	return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getPayload()));
}
 
Example 16
Source File: ResolvableMethod.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static ResolvableType toResolvableType(Class<?> type, ResolvableType generic, ResolvableType... generics) {
	ResolvableType[] genericTypes = new ResolvableType[generics.length + 1];
	genericTypes[0] = generic;
	System.arraycopy(generics, 0, genericTypes, 1, generics.length);
	return ResolvableType.forClassWithGenerics(type, genericTypes);
}
 
Example 17
Source File: FunctionTypeUtils.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static ResolvableType fromTwoArityFunction(Method functionalMethod) {
	return  ResolvableType.forClassWithGenerics(Tuple2.class,
			ResolvableType.forMethodParameter(functionalMethod, 0),
			ResolvableType.forMethodParameter(functionalMethod, 1));
}
 
Example 18
Source File: ResolvableMethod.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static ResolvableType toResolvableType(Class<?> type, ResolvableType generic, ResolvableType... generics) {
	ResolvableType[] genericTypes = new ResolvableType[generics.length + 1];
	genericTypes[0] = generic;
	System.arraycopy(generics, 0, genericTypes, 1, generics.length);
	return ResolvableType.forClassWithGenerics(type, genericTypes);
}
 
Example 19
Source File: ApplicationListenerMethodAdapterTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private ResolvableType createGenericEventType(Class<?> payloadType) {
	return ResolvableType.forClassWithGenerics(PayloadApplicationEvent.class, payloadType);
}
 
Example 20
Source File: TypeDescriptor.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new type descriptor from a {@link java.util.Collection} type.
 * <p>Useful for converting to typed Collections.
 * <p>For example, a {@code List<String>} could be converted to a
 * {@code List<EmailAddress>} by converting to a targetType built with this method.
 * The method call to construct such a {@code TypeDescriptor} would look something
 * like: {@code collection(List.class, TypeDescriptor.valueOf(EmailAddress.class));}
 * @param collectionType the collection type, which must implement {@link Collection}.
 * @param elementTypeDescriptor a descriptor for the collection's element type,
 * used to convert collection elements
 * @return the collection type descriptor
 */
public static TypeDescriptor collection(Class<?> collectionType, TypeDescriptor elementTypeDescriptor) {
	Assert.notNull(collectionType, "Collection type must not be null");
	if (!Collection.class.isAssignableFrom(collectionType)) {
		throw new IllegalArgumentException("Collection type must be a [java.util.Collection]");
	}
	ResolvableType element = (elementTypeDescriptor != null ? elementTypeDescriptor.resolvableType : null);
	return new TypeDescriptor(ResolvableType.forClassWithGenerics(collectionType, element), null, null);
}