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

The following examples show how to use org.springframework.core.ResolvableType#forArrayComponent() . 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: Bindable.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
private static ResolvableType box(ResolvableType type) {
    Class<?> resolved = type.resolve();
    if (resolved != null && resolved.isPrimitive()) {
        Object array = Array.newInstance(resolved, 1);
        Class<?> wrapperType = Array.get(array, 0).getClass();
        return ResolvableType.forClass(wrapperType);
    }
    if (resolved != null && resolved.isArray()) {
        return ResolvableType.forArrayComponent(box(type.getComponentType()));
    }
    return type;
}
 
Example 2
Source File: WxMessageReturnValueHandler.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
    if (returnType.hasMethodAnnotation(WxMapping.class)) {
        return false;
    }
    ResolvableType resolvableType = ResolvableType.forMethodParameter(returnType);
    ResolvableType arrayType = ResolvableType.forArrayComponent(ResolvableType.forClass(WxMessage.class));
    ResolvableType iterableType = ResolvableType.forClassWithGenerics(Iterable.class, WxMessage.class);
    return arrayType.isAssignableFrom(resolvableType) || iterableType.isAssignableFrom(resolvableType);
}
 
Example 3
Source File: SpringBootTest.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
public static void main1(String[] args) throws NoSuchMethodException {
    Method method = WxApp.class.getMethod("cardMessage", String.class);
    ResolvableType resolvableType = ResolvableType.forMethodReturnType(method);
    ResolvableType arrayType = ResolvableType.forArrayComponent(ResolvableType.forClass(WxMessage.class));
    ResolvableType iterableType = ResolvableType.forClassWithGenerics(Iterable.class, WxMessage.class);

    System.out.println(resolvableType);
}
 
Example 4
Source File: TypeDescriptor.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Create a new type descriptor as an array of the specified type.
 * <p>For example to create a {@code Map<String,String>[]} use:
 * <pre class="code">
 * TypeDescriptor.array(TypeDescriptor.map(Map.class, TypeDescriptor.value(String.class), TypeDescriptor.value(String.class)));
 * </pre>
 * @param elementTypeDescriptor the {@link TypeDescriptor} of the array element or {@code null}
 * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null}
 * @since 3.2.1
 */
@Nullable
public static TypeDescriptor array(@Nullable TypeDescriptor elementTypeDescriptor) {
	if (elementTypeDescriptor == null) {
		return null;
	}
	return new TypeDescriptor(ResolvableType.forArrayComponent(elementTypeDescriptor.resolvableType),
			null, elementTypeDescriptor.getAnnotations());
}
 
Example 5
Source File: TypeDescriptor.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Create a new type descriptor as an array of the specified type.
 * <p>For example to create a {@code Map<String,String>[]} use:
 * <pre class="code">
 * TypeDescriptor.array(TypeDescriptor.map(Map.class, TypeDescriptor.value(String.class), TypeDescriptor.value(String.class)));
 * </pre>
 * @param elementTypeDescriptor the {@link TypeDescriptor} of the array element or {@code null}
 * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null}
 * @since 3.2.1
 */
@Nullable
public static TypeDescriptor array(@Nullable TypeDescriptor elementTypeDescriptor) {
	if (elementTypeDescriptor == null) {
		return null;
	}
	return new TypeDescriptor(ResolvableType.forArrayComponent(elementTypeDescriptor.resolvableType),
			null, elementTypeDescriptor.getAnnotations());
}
 
Example 6
Source File: TypeDescriptor.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new type descriptor as an array of the specified type.
 * <p>For example to create a {@code Map<String,String>[]} use:
 * <pre class="code">
 * TypeDescriptor.array(TypeDescriptor.map(Map.class, TypeDescriptor.value(String.class), TypeDescriptor.value(String.class)));
 * </pre>
 * @param elementTypeDescriptor the {@link TypeDescriptor} of the array element or {@code null}
 * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null}
 * @since 3.2.1
 */
public static TypeDescriptor array(TypeDescriptor elementTypeDescriptor) {
	if (elementTypeDescriptor == null) {
		return null;
	}
	return new TypeDescriptor(ResolvableType.forArrayComponent(elementTypeDescriptor.resolvableType),
			null, elementTypeDescriptor.getAnnotations());
}
 
Example 7
Source File: TypeDescriptor.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new type descriptor as an array of the specified type.
 * <p>For example to create a {@code Map<String,String>[]} use:
 * <pre class="code">
 * TypeDescriptor.array(TypeDescriptor.map(Map.class, TypeDescriptor.value(String.class), TypeDescriptor.value(String.class)));
 * </pre>
 * @param elementTypeDescriptor the {@link TypeDescriptor} of the array element or {@code null}
 * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null}
 * @since 3.2.1
 */
public static TypeDescriptor array(TypeDescriptor elementTypeDescriptor) {
	if (elementTypeDescriptor == null) {
		return null;
	}
	return new TypeDescriptor(ResolvableType.forArrayComponent(elementTypeDescriptor.resolvableType),
			null, elementTypeDescriptor.getAnnotations());
}