简体   繁体   中英

Encoding issue for generated source mapper in Mapstruct on IDEA

I'm using Mapstruct for generating dto objects for my entities. I'm using IntelliJ on windows 10 in Turkish on my laptop. 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. 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). But it didnt work.

Maven for the first scenario looks like this.

 ...
   <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. And i managed to generate mapper classes with i instead ı. But on make module it fails and all i characters in class changed to ?.

 <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). 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. We changed -J-Dfile.encoding=UTF-8 to -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. But with same config i cant make module succesfully after build access in maven. I also tried to set MAVEN_OPTS

- 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. I'm using 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.

The editor and compiler must use the same encoding. The change to UTF-8 is advisable on principle, so let's see.

  • Try it all out in a test project.
  • Have an external editor to check the encoding like Notepad++ or JEdit.
  • Change the encoding to UTF-8 (POM, possibly other places)
  • Leave the IDE
  • Check that the encoding did not get automagically converted to UTF-8
  • Convert all sorces to UTF-8.
  • Start the 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

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

Is decisive. Check that project.build.sourceEncoding=UTF-8 .

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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