@Override public boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { return this.conversionService.canConvert(sourceType, targetType); }
/** * Validate that a {@link Collection} of the elements held within the stream can be * converted to the specified {@code targetType}. * @param elementType the type of the stream elements * @param targetType the type to convert to */ public boolean matchesFromStream(@Nullable TypeDescriptor elementType, TypeDescriptor targetType) { TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType); return this.conversionService.canConvert(collectionOfElement, targetType); }
/** * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of * the type of the stream elements. * @param elementType the type of the stream elements * @param sourceType the type to convert from */ public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescriptor sourceType) { TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType); return this.conversionService.canConvert(sourceType, collectionOfElement); }
@Override public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) { return canRead(mediaType) && this.conversionService.canConvert(String.class, clazz); }
@Override public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) { return canWrite(mediaType) && this.conversionService.canConvert(clazz, String.class); }
private boolean matchesFromByteBuffer(TypeDescriptor targetType) { return (targetType.isAssignableTo(BYTE_ARRAY_TYPE) || this.conversionService.canConvert(BYTE_ARRAY_TYPE, targetType)); }
@Override public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) { return this.service.canConvert(sourceType, targetType); }
private boolean matchesToByteBuffer(TypeDescriptor sourceType) { return (sourceType.isAssignableTo(BYTE_ARRAY_TYPE) || this.conversionService.canConvert(sourceType, BYTE_ARRAY_TYPE)); }
/** * Create a new ConvertingPropertyEditorAdapter for a given * {@link org.springframework.core.convert.ConversionService} * and the given target type. * @param conversionService the ConversionService to delegate to * @param targetDescriptor the target type to convert to */ public ConvertingPropertyEditorAdapter(ConversionService conversionService, TypeDescriptor targetDescriptor) { Assert.notNull(conversionService, "ConversionService must not be null"); Assert.notNull(targetDescriptor, "TypeDescriptor must not be null"); this.conversionService = conversionService; this.targetDescriptor = targetDescriptor; this.canConvertToString = conversionService.canConvert(this.targetDescriptor, TypeDescriptor.valueOf(String.class)); }
@Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { return (targetType.getElementTypeDescriptor() == null || this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor())); }
@Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { Method finder = getFinder(targetType.getType()); return (finder != null && this.conversionService.canConvert(sourceType, TypeDescriptor.valueOf(finder.getParameterTypes()[0]))); }
@Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { for (Class<?> interfaceType : ClassUtils.getAllInterfacesForClassAsSet(sourceType.getType())) { if (this.conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) { return false; } } return true; }
/** * Determine if a given message can be decoded. * @see #decode(Object) * @see javax.websocket.Decoder.Text#willDecode(String) * @see javax.websocket.Decoder.Binary#willDecode(ByteBuffer) */ public boolean willDecode(M bytes) { return getConversionService().canConvert(getType(), getMessageType()); }
@Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { if (targetType.getResolvableType().hasGenerics()) { return this.conversionService.canConvert(sourceType, new GenericTypeDescriptor(targetType)); } else { return true; } }
public boolean canConvert(Class<?> sourceType, Class<?> targetType) { if (conversionService.canConvert(sourceType, targetType)) { return true; } if (!String.class.isAssignableFrom(sourceType) && !String.class.isAssignableFrom(targetType)) { // PropertyEditor cannot convert non-Strings return false; } if (!String.class.isAssignableFrom(sourceType)) { return delegate.findCustomEditor(sourceType, null) != null || delegate.getDefaultEditor(sourceType) != null; } return delegate.findCustomEditor(targetType, null) != null || delegate.getDefaultEditor(targetType) != null; }
@Override public boolean canConvert(TypeDescriptor sourceTypeDescriptor, TypeDescriptor targetTypeDescriptor) { if (conversionService.canConvert(sourceTypeDescriptor, targetTypeDescriptor)) { return true; } // TODO: what does this mean? This method is not used in SpEL so probably ignorable? Class<?> sourceType = sourceTypeDescriptor.getObjectType(); Class<?> targetType = targetTypeDescriptor.getObjectType(); return canConvert(sourceType, targetType); }
@Test public void createDefaultConversionService() { ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean(); factory.afterPropertiesSet(); ConversionService service = factory.getObject(); assertTrue(service.canConvert(String.class, Integer.class)); }
@Test public void testWithConversionService() { ConversionService conversionService = new DefaultConversionService(); assertTrue(conversionService.canConvert(String.class, MediaType.class)); MediaType mediaType = MediaType.parseMediaType("application/xml"); assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class)); }
@Test public void withConversionService() { ConversionService conversionService = new DefaultConversionService(); assertTrue(conversionService.canConvert(String.class, MimeType.class)); MimeType mimeType = MimeType.valueOf("application/xml"); assertEquals(mimeType, conversionService.convert("application/xml", MimeType.class)); }
@Override public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType) { if (targetType.getType() == Void.class || targetType.getType() == Void.TYPE) { return null; } if (conversionService.canConvert(sourceType, targetType)) { return conversionService.convert(value, sourceType, targetType); } if (!String.class.isAssignableFrom(sourceType.getType())) { PropertyEditor editor = delegate.findCustomEditor(sourceType.getType(), null); editor.setValue(value); return editor.getAsText(); } return delegate.convertIfNecessary(value, targetType.getType()); }