如何使Spring的ConditionalGenericConverter成为泛型类型?

时间:2019-12-03 13:30:41

标签: java spring spring-mvc

我正在制作转换器StringToMyGeneric。而且我一直坚持实施,我到底如何进行这种转换。

public class StringToMyGenericConverter implements ConditionalGenericConverter {

    ...

    @Override
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

        //This is what I came to 
        if (source == null) {
            return new MyGeneric<>((long) 0);
        }
        Class<?> valueType = (Class<Identifier>) targetType.getResolvableType().resolveGeneric(0);
        Object convert = conversionService.convert(source, valueType);

        targetType.getResolvableType().resolveGeneric(0);

        //This is what I want to return
        long myLongValue = ...
        return new Identifier<>(myLongValue);
    }
}

有人有经验吗?

0 个答案:

没有答案