[英]Encoding issue for generated source mapper in Mapstruct on IDEA
我正在使用Mapstruct为我的实体生成dto对象。 我在笔记本电脑上以土耳其语的Windows 10操作系统上使用IntelliJ。 我的问题正在关注。
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2016-09-05T16:36:08+0300",
comments = "version: 1.0.0.Final, compiler: javac, environment: Java 1.8.0_74 (Oracle Corporation)"
)
public class VeininvoiceMapperImpl implements VeininvoiceMapper {
private final LocalDateMapper localDateMapper = Mappers.getMapper( LocalDateMapper.class );
private final BoxTypeMapper boxTypeMapper = Mappers.getMapper( BoxTypeMapper.class );
private final InvoiceStatusCodeMapper ınvoiceStatusCodeMapper = Mappers.getMapper( InvoiceStatusCodeMapper.class );
private final SenderLabelMapper senderLabelMapper = Mappers.getMapper( SenderLabelMapper.class );
private final PostboxLabelMapper postboxLabelMapper = Mappers.getMapper( PostboxLabelMapper.class );
private final VeinpartnerMapper veinpartnerMapper = Mappers.getMapper( VeinpartnerMapper.class );
@Override
public Invoice veininvoiceToDto(Veininvoice veininvoice) {
if ( veininvoice == null ) {
return null;
}
Invoice ınvoice = new Invoice();
ınvoice.setInvoiceStatusCode( ınvoiceStatusCodeMapper.statusToDto( veininvoice.getInvoicestatuscode() ) );
ınvoice.setBoxType( boxTypeMapper.boxtypeToDto( veininvoice.getBoxtype() ) );
ınvoice.setPartner( veinpartnerMapper.veinpartnerToDto( veininvoice.getVeinpartner() ) );
ınvoice.setInvoiceNr( veininvoice.getInvoiceNr() );
ınvoice.setIsarchive( veininvoice.getIsarchive() );
ınvoice.setUblversionid( veininvoice.getUblversionid() );
ınvoice.setCustomizationid( veininvoice.getCustomizationid() );
ınvoice.setCopyindicator( veininvoice.getCopyindicator() );
ınvoice.setIssuedate( localDateMapper.issueDateToCalendar( veininvoice.getIssuedate() ) );
ınvoice.setIssuetime( veininvoice.getIssuetime() );
ınvoice.setServicetypecode( veininvoice.getServicetypecode() );
ınvoice.setNote( veininvoice.getNote() );
ınvoice.setCurrencycode( veininvoice.getCurrencycode() );
ınvoice.setLinecountnumeric( veininvoice.getLinecountnumeric() );
ınvoice.setIsactive( veininvoice.getIsactive() );
ınvoice.setSenderLabel( senderLabelMapper.senderLabeltoDto( veininvoice.getSenderLabel() ) );
ınvoice.setPostboxLabel( postboxLabelMapper.postboxLabelToDto( veininvoice.getPostboxLabel() ) );
ınvoice.setId( veininvoice.getId() );
ınvoice.setUuid( veininvoice.getUuid() );
return ınvoice;
}
如您所见,变量名称创建为ı而不是i。 如果我尝试部署或制作模块。 它失败,并且班上所有的ı字符都变成'?' 喜欢以下。 。
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2016-09-05T16:39:20+0300",
comments = "version: 1.0.0.Final, compiler: javac, environment: Java 1.8.0_74 (Oracle Corporation)"
)
public class VeininvoiceMapperImpl implements VeininvoiceMapper {
private final LocalDateMapper localDateMapper = Mappers.getMapper( LocalDateMapper.class );
private final BoxTypeMapper boxTypeMapper = Mappers.getMapper( BoxTypeMapper.class );
private final InvoiceStatusCodeMapper ?nvoiceStatusCodeMapper = Mappers.getMapper( InvoiceStatusCodeMapper.class );
private final SenderLabelMapper senderLabelMapper = Mappers.getMapper( SenderLabelMapper.class );
private final PostboxLabelMapper postboxLabelMapper = Mappers.getMapper( PostboxLabelMapper.class );
private final VeinpartnerMapper veinpartnerMapper = Mappers.getMapper( VeinpartnerMapper.class );
@Override
public Invoice veininvoiceToDto(Veininvoice veininvoice) {
if ( veininvoice == null ) {
return null;
}
Invoice ?nvoice = new Invoice();
?nvoice.setInvoiceStatusCode( ?nvoiceStatusCodeMapper.statusToDto( veininvoice.getInvoicestatuscode() ) );
?nvoice.setBoxType( boxTypeMapper.boxtypeToDto( veininvoice.getBoxtype() ) );
?nvoice.setPartner( veinpartnerMapper.veinpartnerToDto( veininvoice.getVeinpartner() ) );
我试图将文件和整个项目的编码设置为UTF-8(设置->文件编码)。 但是它没有用。
第一种情况的Maven看起来像这样。
...
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
<scope>provided</scope>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source> <!-- or higher, depending on your project -->
<target>1.8</target> <!-- or higher, depending on your project -->
<encoding>${project.build.sourceEncoding}</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
然后我将Maven配置更改为以下内容。 我设法与我相反生成了映射器类。 但是在make模块上它失败,并且类中的所有i字符都更改为?。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-J-Duser.language=en_us</arg>
<arg>-J-Dfile.encoding=UTF-8</arg>
</compilerArgs>
<source>1.8</source> <!-- or higher, depending on your project -->
<target>1.8</target> <!-- or higher, depending on your project -->
<encoding>${project.build.sourceEncoding}</encoding>
<!--<proc>none</proc> <!– disable annotation processing to avoid duplicating maven-processor-plugin output –>-->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
更有趣的是,为了对其进行测试,我创建了一个仅具有映射器依赖项以及Object和DTO(ITestObject)的示例项目。 我把它给了我的同事。 他具有与Java和Intellij完全相同的版本,并且还在笔记本电脑上安装了Windows 10 Turkish。 我们将-J-Dfile.encoding = UTF-8更改为-J-Dfile.encoding = windows-1254。 构建成功后,他制作模块没有任何问题。 文件尚未损坏。 以防万一重新编译模块,他也像我一样损坏了Mapper文件。 但是使用相同的配置,我无法在Maven中建立访问后成功制作模块。 我也尝试设置MAVEN_OPTS
Dfile.encoding=UTF-8 -Duser.country=TR -Duser.language=es -Duser.variant=Traditional_WIN
但不幸的是它没有用。 我认为,问题与IntelliJ操作系统有关。 我正在使用IDEA 2016.2.3,Maven 3.3.9。 有人知道为什么会发生或与之相关吗? 提前致谢。
我认为原始的Java来源是Latin-3。
编辑器和编译器必须使用相同的编码。 原则上建议对UTF-8进行更改,让我们来看一下。
然后它可能无法正常工作。 Maven的-Dfile.encoding=UTF-8
是正确的属性,但不是必需的
<encoding>${project.build.sourceEncoding}</encoding>
是决定性的。 检查project.build.sourceEncoding=UTF-8
。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.