Expected behavior
In Java 20 and later, the URL(String) constructor has been deprecated in favor of using URI to handle the parsing logic:
if ( url != null ) {
url1 = URI.create( url ).toURL();
}
Actual behavior
Currently, MapStruct generates code using the deprecated constructor when mapping a String to a java.net.URL:
if ( url != null ) {
url1 = new URL( url );
}
Steps to reproduce the problem
- Use Java 20 or higher.
- Define a mapper that converts a
String to a java.net.URL (or a record/bean containing a URL).
- Observe the generated implementation.
Example:
@Mapper
public interface ProductMapper {
Product map(String url) throws MalformedURLException;
record Product(URL url) {}
}
Generated implementation:
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2026-04-23T12:14:28+0300",
comments = "version: 1.6.3, compiler: IncrementalProcessingEnvironment from gradle-language-java-9.4.1.jar, environment: Java 25.0.1 (Eclipse Adoptium)"
)
public class ProductMapperImpl implements ProductMapper {
@Override
public ProductMapper.Product map(String url) throws MalformedURLException {
if ( url == null ) {
return null;
}
URL url1 = null;
if ( url != null ) {
url1 = new URL( url );
}
ProductMapper.Product product = new ProductMapper.Product( url1 );
return product;
}
}
Compiling the mapper above will produce the following message in the console output:
Note: C:\Users\Yevhen\IdeaProjects\gradle-mapstruct-demo\build\generated\sources\annotationProcessor\java\main\io\github\yvasyliev\mapstruct\ProductMapperImpl.java uses or overrides a deprecated API.
MapStruct Version
1.6.3
Expected behavior
In Java 20 and later, the
URL(String)constructor has been deprecated in favor of usingURIto handle the parsing logic:Actual behavior
Currently, MapStruct generates code using the deprecated constructor when mapping a
Stringto ajava.net.URL:Steps to reproduce the problem
Stringto ajava.net.URL(or a record/bean containing aURL).Example:
Generated implementation:
Compiling the mapper above will produce the following message in the console output:
MapStruct Version
1.6.3