How can I convert Optional List object from one type to another, for an example
Optional<List<ProductMultipleOptionViewModel>> productOptionType1 // One type
Optional<List<ProductMultipleOption>> productOptionType2 // Other type
ProductMultipleOptionViewModel
Type 1
@Introspected
public record ProductMultipleOptionViewModel(
        ProductOptionViewModel productOption,
        String optionName) {
}
Type 2
 @Introspected
    public record ProductMultipleOption(
            ProductOptionViewModel productOption,
            String optionName) {
    }
I want to convert from Optional<List<ProductMultipleOption>>to other Optional<List<ProductMultipleOptionViewModel>>. I tried the below code
Optional<List<ProductMultipleOptionViewModel>> conveertItem = Optional.ofNullable(product.getProductMultipleOption())
                .orElseGet(null)
                .stream()
                .map(option -> {
                    return new ProductMultipleOptionViewModel(
                            ProductOptionViewModel.valueOf(//Access the option value//), //access the option value//
                    );
                })
                .collect(Collectors.toList());
With the above code, I am not able to access the option value inside map method
If product.getProductMultipleOption() is null return null or empty list.
 
     
     
    