本文整理汇总了Java中org.springframework.data.convert.ReadingConverter类的典型用法代码示例。如果您正苦于以下问题:Java ReadingConverter类的具体用法?Java ReadingConverter怎么用?Java ReadingConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadingConverter类属于org.springframework.data.convert包,在下文中一共展示了ReadingConverter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerConversion
import org.springframework.data.convert.ReadingConverter; //导入依赖的package包/类
private void registerConversion(Object converter) {
Class<?> type = converter.getClass();
boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
boolean isReading = type.isAnnotationPresent(ReadingConverter.class);
if (!isReading && !isWriting) {
isReading = true;
isWriting = true;
}
if (converter instanceof GenericConverter) {
GenericConverter genericConverter = (GenericConverter) converter;
for (ConvertiblePair pair : genericConverter.getConvertibleTypes()) {
register(new ConvertibleContext(pair, isReading, isWriting));
}
} else if (converter instanceof Converter) {
Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
register(new ConvertibleContext(arguments[0], arguments[1], isReading, isWriting));
} else {
throw new IllegalArgumentException("Unsupported Converter type! Expected either GenericConverter if Converter.");
}
}
示例2: registerConversion
import org.springframework.data.convert.ReadingConverter; //导入依赖的package包/类
/**
* Registers a conversion for the given converter. Inspects either generics or the convertible pairs returned
* by a {@link GenericConverter}.
*
* @param converter the converter to register.
*/
private void registerConversion(final Object converter) {
Class<?> type = converter.getClass();
boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
boolean isReading = type.isAnnotationPresent(ReadingConverter.class);
if (converter instanceof GenericConverter) {
GenericConverter genericConverter = (GenericConverter) converter;
for (GenericConverter.ConvertiblePair pair : genericConverter.getConvertibleTypes()) {
register(new ConverterRegistration(pair, isReading, isWriting));
}
} else if (converter instanceof Converter) {
Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
register(new ConverterRegistration(arguments[0], arguments[1], isReading, isWriting));
} else {
throw new IllegalArgumentException("Unsupported Converter type!");
}
}