I have the following Spring converter:
@Component
public class MyObjectToStringList implements Converter<MyObject, List<String>>{
@Override
public List<String> convert(MyObject obj) {
List<String> items = new ArrayList<>(
Arrays.asList(
obj.get().split("\\r?\\n")));
items.remove(0);
return items;
}
}
In another component, I use the converter via the conversion service:
@Component
@RequiredArgsConstructor
public class MyService {
private final ConversionService conversionService;
public List<String> get(MyObject obj) {
@SuppressWarnings("unchecked")
List<String> rows = (List<String>) conversionService.convert(obj, List.class);
This works but is there anyway to avoid the unchecked cast?