简体   繁体   English

IDEA上Mapstruct中生成的源映射器的编码问题

[英]Encoding issue for generated source mapper in Mapstruct on IDEA

I'm using Mapstruct for generating dto objects for my entities. 我正在使用Mapstruct为我的实体生成dto对象。 I'm using IntelliJ on windows 10 in Turkish on my laptop. 我在笔记本电脑上以土耳其语的Windows 10操作系统上使用IntelliJ。 My Problem was following. 我的问题正在关注。

 @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;
    }

as you see, variable names created as ı instead i. 如您所见,变量名称创建为ı而不是i。 And if i try to deploy or make module. 如果我尝试部署或制作模块。 it fails and all ı characters in class become '?' 它失败,并且班上所有的ı字符都变成'?' like following. 喜欢以下。 .

  @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() ) );

i tried to set encoding for file and for whole project to UTF-8 ( settings -> File Encodings). 我试图将文件和整个项目的编码设置为UTF-8(设置->文件编码)。 But it didnt work. 但是它没有用。

Maven for the first scenario looks like this. 第一种情况的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>

then i changed the maven configuration to following. 然后我将Maven配置更改为以下内容。 And i managed to generate mapper classes with i instead ı. 我设法与我相反生成了映射器类。 But on make module it fails and all i characters in class changed to ?. 但是在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> &lt;!&ndash; disable annotation processing to avoid duplicating maven-processor-plugin output &ndash;&gt;-->
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

more interestingly, in order to test it, i have created a sample project just with mapper dependencies and an Object and DTO (ITestObject). 更有趣的是,为了对其进行测试,我创建了一个仅具有映射器依赖项以及Object和DTO(ITestObject)的示例项目。 And i gave it to my colleague. 我把它给了我的同事。 He has exactly same version for Java and Intellij and also installed windows 10 Turkish on his laptop. 他具有与Java和Intellij完全相同的版本,并且还在笔记本电脑上安装了Windows 10 Turkish。 We changed -J-Dfile.encoding=UTF-8 to -J-Dfile.encoding=windows-1254. 我们将-J-Dfile.encoding = UTF-8更改为-J-Dfile.encoding = windows-1254。 he made module without any problems after Build Success. 构建成功后,他制作模块没有任何问题。 File has not been corrupted. 文件尚未损坏。 just in case recompile module he had also corrupted Mapper file as me. 以防万一重新编译模块,他也像我一样损坏了Mapper文件。 But with same config i cant make module succesfully after build access in maven. 但是使用相同的配置,我无法在Maven中建立访问后成功制作模块。 I also tried to set MAVEN_OPTS 我也尝试设置MAVEN_OPTS

- Dfile.encoding=UTF-8 -Duser.country=TR -Duser.language=es -Duser.variant=Traditional_WIN Dfile.encoding=UTF-8 -Duser.country=TR -Duser.language=es -Duser.variant=Traditional_WIN

But unfortunately it didnt work. 但不幸的是它没有用。 I think, problem is somehow related to OS with IntelliJ. 我认为,问题与IntelliJ操作系统有关。 I'm using IDEA 2016.2.3, Maven 3.3.9. 我正在使用IDEA 2016.2.3,Maven 3.3.9。 Does someone have an idea why its happens or what it can be related to ? 有人知道为什么会发生或与之相关吗? Thanks in Advance. 提前致谢。

I take it the original java sources were in Latin-3. 我认为原始的Java来源是Latin-3。

The editor and compiler must use the same encoding. 编辑器和编译器必须使用相同的编码。 The change to UTF-8 is advisable on principle, so let's see. 原则上建议对UTF-8进行更改,让我们来看一下。

  • Try it all out in a test project. 在测试项目中全部尝试。
  • Have an external editor to check the encoding like Notepad++ or JEdit. 使用外部编辑器检查诸如Notepad ++或JEdit之类的编码。
  • Change the encoding to UTF-8 (POM, possibly other places) 将编码更改为UTF-8(POM,可能在其他地方)
  • Leave the IDE 离开IDE
  • Check that the encoding did not get automagically converted to UTF-8 检查编码没有自动转换为UTF-8
  • Convert all sorces to UTF-8. 将所有源转换为UTF-8。
  • Start the IDE 启动IDE
  • Do a clean, build all. 做一个清洁,建立所有。

And then it probably did not work. 然后它可能无法正常工作。 The -Dfile.encoding=UTF-8 for maven is the right property, but non needed Maven的-Dfile.encoding=UTF-8是正确的属性,但不是必需的

<encoding>${project.build.sourceEncoding}</encoding>

Is decisive. 是决定性的。 Check that project.build.sourceEncoding=UTF-8 . 检查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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM