mapstruct / mapstruct-examples

Examples for using MapStruct
Other
1.28k stars 511 forks source link

mapstruct-protobuf3 use lombok:UnsupportedOperationException(Collections$UnmodifiableCollection) #142

Open minzhiwu opened 1 year ago

minzhiwu commented 1 year ago

modify mapstruct-protobuf3/usage/pom.xml plugin config,

                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>

                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${org.projectlombok.version}</version>
                    </path>

                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok-mapstruct-binding</artifactId>
                        <version>${lombok-mapstruct-binding.version}</version>
                    </path>

                    <path>
                        <!-- Add your SPI implementation. -->
                        <groupId>org.mapstruct.examples.spi</groupId>
                        <artifactId>protobuf-spi-impl</artifactId>
                        <version>1.0.0</version>
                    </path>

                </annotationProcessorPaths>
   `

rebuild the mapstruct-protobuf3, run the test,report an error java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableCollection.addAll(Collections.java:1065) at org.mapstruct.example.mapper.UserMapperImpl.map(UserMapperImpl.java:34) at org.mapstruct.example.ProtobufTest.test(ProtobufTest.java:33),

Partially generated code

if ( userDTO.getMainDepartmentsList() != null ) {
           List<UserProtos.DepartmentDTO> list = departmentListToDepartmentDTOList( user.getMainDepartments() );
            if ( list != null ) {
                userDTO.getMainDepartmentsList().addAll( list );
            }

        }
        if ( userDTO.getDepartmentsList() != null ) {

            List<UserProtos.DepartmentDTO> list1 = departmentListToDepartmentDTOList( user.getDepartments() );
            if ( list1 != null ) {
                userDTO.getDepartmentsList().addAll( list1 );
            }

recover mapstruct-protobuf3/usage/pom.xml plugin config, run test success. Is there any way to solve this problem?