Spring Framework TypeDescriptor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework TypeDescriptor class.

This code example shows how to use the following methods:getAnnotations, getResolvableType
 
	@SuppressWarnings("serial") 
	private static class GenericTypeDescriptor extends TypeDescriptor {
 
		public GenericTypeDescriptor(TypeDescriptor typeDescriptor) {
			super(typeDescriptor.getResolvableType().getGeneric(0), null, typeDescriptor.getAnnotations());
		} 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:
 
		DataBinder binder = binderFactory.createBinder(request, null, attributeName); 
		ConversionService conversionService = binder.getConversionService(); 
		if (conversionService != null) { 
			TypeDescriptor source = TypeDescriptor.valueOf(String.class); 
			TypeDescriptor target = new TypeDescriptor(parameter); 
			if (conversionService.canConvert(source, target)) { 
				return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter); 
			} 
		} 
		return null; 
	} 
 
	/** 
	 * This implementation downcasts {@link WebDataBinder} to 
	 * {@link ServletRequestDataBinder} before binding. 
	 * @see ServletRequestDataBinderFactory 
	 */ 
	@Override 
	protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) { 
6
CodeRank
This code example shows how to use the following methods:
	public void scalarList() throws Exception {
		List<String> list = new ArrayList<String>();
		list.add("9");
		list.add("37");
		TypeDescriptor sourceType = TypeDescriptor.forObject(list);
		TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarListTarget"));
		assertTrue(conversionService.canConvert(sourceType, targetType));
		try { 
			conversionService.convert(list, sourceType, targetType);
		} 
		catch (ConversionFailedException ex) {
			assertTrue(ex.getCause() instanceof ConverterNotFoundException);
		} 
		conversionService.addConverterFactory(new StringToNumberConverterFactory());
		assertTrue(conversionService.canConvert(sourceType, targetType));
		@SuppressWarnings("unchecked") 
		List<String> result = (List<String>) conversionService.convert(list, sourceType, targetType);
		assertFalse(list.equals(result));
		assertEquals(9, result.get(0));
		assertEquals(37, result.get(1));

6
CodeRank
This code example shows how to use the following methods:getObjectType
		return Collections.singleton(new ConvertiblePair(Object.class, String.class));
	} 
 
	@Override 
	public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
		Class<?> sourceClass = sourceType.getObjectType();
		if (String.class.equals(sourceClass)) {
			return false; 
		} 
		return (CharSequence.class.isAssignableFrom(sourceClass) ||
				StringWriter.class.isAssignableFrom(sourceClass) ||
				ObjectToObjectConverter.getOfMethod(sourceClass, String.class) != null ||
				ClassUtils.getConstructorIfAvailable(sourceClass, String.class) != null);
	} 
 
	@Override 
	public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
		return (source != null ? source.toString() : null);
	} 
 
6
CodeRank
This code example shows how to use the following methods:isAssignableTo
	@Override 
	public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
		if (sourceType.isAssignableTo(BYTE_BUFFER_TYPE)) {
			return matchesFromByteBuffer(targetType);
		} 
		if (targetType.isAssignableTo(BYTE_BUFFER_TYPE)) {
			return matchesToByteBuffer(sourceType);
		} 
		return false; 
	} 
 
	private boolean matchesFromByteBuffer(TypeDescriptor targetType) {
		return (targetType.isAssignableTo(BYTE_ARRAY_TYPE) || this.conversionService.canConvert(
				BYTE_ARRAY_TYPE, targetType));
	} 
 
	private boolean matchesToByteBuffer(TypeDescriptor sourceType) {
		return (sourceType.isAssignableTo(BYTE_ARRAY_TYPE) || this.conversionService.canConvert(
				sourceType, BYTE_ARRAY_TYPE));
	} 
6
CodeRank
This code example shows how to use the following methods:isArray, isAssignableTo, isCollection
This code example shows how to use the following methods:
			if (this.method.isVarArgs()) {
				arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(), arguments);
			} 
			ReflectionUtils.makeAccessible(this.method);
			Object value = this.method.invoke(target, arguments);
			return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.method, -1)).narrow(value));
		} 
		catch (Exception ex) {
			throw new AccessException("Problem invoking method: " + this.method, ex);
		} 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getType,
		return Collections.singleton(new ConvertiblePair(Object.class, Object.class));
	} 
 
	@Override 
	public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
		if (sourceType.getType().equals(targetType.getType())) {
			// no conversion required 
			return false; 
		} 
		return (String.class.equals(targetType.getType()) ?
				(ClassUtils.getConstructorIfAvailable(String.class, sourceType.getType()) != null) :
				hasToMethodOrOfMethodOrConstructor(targetType.getType(), sourceType.getType()));
	} 
 
	@Override 
	public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
		if (source == null) {
			return null; 
		} 
		Class<?> sourceClass = sourceType.getType();
5
CodeRank
This code example shows how to use the following methods:getAnnotation, getType
 
	public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { 
		if (SpringFacesContext.getCurrentInstance() == null) { 
			return false; 
		} 
		if (targetType.getAnnotation(FacesConverterId.class) != null) { 
			return true; 
		} 
		FacesContext facesContext = SpringFacesContext.getCurrentInstance().getFacesContext(); 
		Application application = facesContext.getApplication(); 
		return ((application != null) && (application.createConverter(targetType.getType()) != null)); 
	} 
 
	public Object convert(final Object source, final TypeDescriptor sourceType, final TypeDescriptor targetType) { 
		if (source == null) { 
			return null; 
		} 
		SpringFacesContext springFacesContext = SpringFacesContext.getCurrentInstance(); 
		FacesContext facesContext = springFacesContext.getFacesContext(); 
		try { 
5
CodeRank
This code example shows how to use the following methods:getElementTypeDescriptor, isCollection
	public Class<?> getType() {
		return typeDescriptor.getType();
	} 
 
	public Class<?> getCollectionType() {
		if (typeDescriptor.isCollection()
				&& typeDescriptor.getElementTypeDescriptor() != null) {
			return typeDescriptor.getElementTypeDescriptor().getType();
		} 
		return null; 
	} 
 
	public String getName() {
		return name;
	} 
 
	public boolean hasRequestParamAnnotation() { 
		return hasRequestParamAnnotation;
	} 
 
5
CodeRank
See Code Examples for Spring Framework TypeDescriptor Methods: