All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.geewit.web.convert.converter.EnumValueToLongConverter Maven / Gradle / Ivy

The newest version!
package io.geewit.web.convert.converter;

import io.geewit.core.utils.enums.Value;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalConverter;
import org.springframework.core.convert.converter.Converter;


/**
 * 自动转换类型
 * @param 
 * @author geewit
 */
public class EnumValueToLongConverter & Value> implements Converter, ConditionalConverter {

    @Override
    public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
        return sourceType.isAssignableTo(TypeDescriptor.valueOf(Value.class)) && sourceType.isAssignableTo(TypeDescriptor.valueOf(Enum.class));
    }

    @Override
    public Long convert(S source) {
        return source.value();
    }
}