org.springframework.data.convert.WritingConverter Java Examples

The following examples show how to use org.springframework.data.convert.WritingConverter. 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: CustomConversions.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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.");
	}
}
 
Example #2
Source File: CustomConversions.java    From spring-data-crate with Apache License 2.0 6 votes vote down vote up
/**
 * 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!");
  }
}