mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#465 Referencing formatter class by name rather than class object
This commit is contained in:
parent
46145323ac
commit
2c845480a0
@ -23,6 +23,7 @@ import java.util.Set;
|
||||
import org.mapstruct.ap.model.common.ConversionContext;
|
||||
import org.mapstruct.ap.model.common.Type;
|
||||
import org.mapstruct.ap.util.Collections;
|
||||
import org.mapstruct.ap.util.JavaTimeConstants;
|
||||
import org.mapstruct.ap.util.Strings;
|
||||
|
||||
/**
|
||||
@ -83,24 +84,14 @@ public abstract class AbstractJavaTimeToStringConversion extends SimpleConversio
|
||||
@Override
|
||||
protected Set<Type> getToConversionImportTypes(ConversionContext conversionContext) {
|
||||
return Collections.asSet(
|
||||
conversionContext.getTypeFactory().getType( dateTimeFormatterClass() )
|
||||
conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Type> getFromConversionImportTypes(ConversionContext conversionContext) {
|
||||
return Collections.asSet(
|
||||
conversionContext.getTypeFactory().getType( dateTimeFormatterClass() )
|
||||
conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN )
|
||||
);
|
||||
}
|
||||
|
||||
private Class dateTimeFormatterClass() {
|
||||
try {
|
||||
return Class.forName( "java.time.format.DateTimeFormatter" );
|
||||
}
|
||||
catch ( ClassNotFoundException e ) {
|
||||
throw new RuntimeException( "java.time.format.DateTimeFormatter not found on classpath" );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public final class JavaTimeConstants {
|
||||
public static final String LOCAL_DATE_TIME_FQN = "java.time.LocalDateTime";
|
||||
public static final String LOCAL_DATE_FQN = "java.time.LocalDate";
|
||||
public static final String LOCAL_TIME_FQN = "java.time.LocalTime";
|
||||
public static final String DATE_TIME_FORMATTER_FQN = "java.time.format.DateTimeFormatter";
|
||||
|
||||
private JavaTimeConstants() {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user