我正在制作转换器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);
}
}
有人有经验吗?