org.springframework.core.convert.converter.GenericConverter#convert ( )源码实例Demo

下面列出了org.springframework.core.convert.converter.GenericConverter#convert ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = sourceType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
	GenericConverter converter = cachedPrinters.get(converterKey);
	if (converter == null) {
		Printer<?> printer = this.annotationFormatterFactory.getPrinter(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
		cachedPrinters.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = targetType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
	GenericConverter converter = cachedParsers.get(converterKey);
	if (converter == null) {
		Parser<?> parser = this.annotationFormatterFactory.getParser(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
		cachedParsers.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = sourceType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
	GenericConverter converter = cachedPrinters.get(converterKey);
	if (converter == null) {
		Printer<?> printer = this.annotationFormatterFactory.getPrinter(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
		cachedPrinters.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = targetType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
	GenericConverter converter = cachedParsers.get(converterKey);
	if (converter == null) {
		Parser<?> parser = this.annotationFormatterFactory.getParser(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
		cachedParsers.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
源代码5 项目: lams   文件: FormattingConversionService.java
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = sourceType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
	GenericConverter converter = cachedPrinters.get(converterKey);
	if (converter == null) {
		Printer<?> printer = this.annotationFormatterFactory.getPrinter(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
		cachedPrinters.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
源代码6 项目: lams   文件: FormattingConversionService.java
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = targetType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
	GenericConverter converter = cachedParsers.get(converterKey);
	if (converter == null) {
		Parser<?> parser = this.annotationFormatterFactory.getParser(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
		cachedParsers.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = sourceType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
	GenericConverter converter = cachedPrinters.get(converterKey);
	if (converter == null) {
		Printer<?> printer = this.annotationFormatterFactory.getPrinter(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
		cachedPrinters.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}
 
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	Annotation ann = targetType.getAnnotation(this.annotationType);
	if (ann == null) {
		throw new IllegalStateException(
				"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
	}
	AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
	GenericConverter converter = cachedParsers.get(converterKey);
	if (converter == null) {
		Parser<?> parser = this.annotationFormatterFactory.getParser(
				converterKey.getAnnotation(), converterKey.getFieldType());
		converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
		cachedParsers.put(converterKey, converter);
	}
	return converter.convert(source, sourceType, targetType);
}