[Open Source] Possibly the Simplest and Most Powerful Java Bean Conversion Tool, Making Conversions More Convenient and Elegant

Open SourceProcess Management
2026-06-28 05:33 2 次浏览 • 0 次下载 0KB
[Open Source] Possibly the Simplest and Most Powerful Java Bean Conversion Tool, Making Conversions More Convenient and Elegant

1. Project Overview

MapStructPlus

Possibly the Simplest and Most Powerful Java Bean Conversion Tool

MapStruct Plus is an enhanced tool for MapStruct. Building on MapStruct, it provides automatic generation of Mapper interfaces and enhances certain features, making Java type conversion more convenient and elegant.

2. Open Source License

Licensed under Apache-2.0

3. Screenshots

Image

4. Feature Overview

MapStruct Plus is an enhancement to the MapStruct framework. It adds functionality without modifying the original framework. With a single annotation, it can automatically generate conversion operations between two classes, eliminating the need to manually define MapStruct interfaces and making Java type conversion more convenient and elegant.

Goal: Build the Simplest and Most Powerful Type Conversion Tool

Features

Fast

Converting between Java classes requires only one additional annotation, reducing tedious and error-prone development tasks.

Efficient

Based on annotation processing, all code generation is completed at compile time.

Conversion

Property conversion is based on getter/setter methods in classes.

Compatible

Supports JDK 8–17 and Spring Boot 2–3.

Multiple Class Conversions

Supports configuring multiple type conversions for a single class.

Map to Object

More Powerful Map-to-Object Conversion

5. Tech Stack

Quick Start

The following example demonstrates how to use MapStruct Plus to map two objects.

Suppose there are two classes, UserDto and User, representing the data layer object and business layer object, respectively:

  • UserDto

public class UserDto {
    private String username;
    private int age;
    private boolean young;

    // getter、setter、toString、equals、hashCode
}
  • User

public class User {
    private String username;
    private int age;
    private boolean young;

    // getter、setter、toString、equals、hashCode
}

Add Dependencies

Import
Add the mapstruct-plus-spring-boot-starter dependency:

<properties>
    <mapstruct-plus.version>1.4.3</mapstruct-plus.version>
</properties>
<dependencies>
    <dependency>
        <groupId>io.github.linpeilie</groupId>
        <artifactId>mapstruct-plus-spring-boot-starter</artifactId>
        <version>${mapstruct-plus.version}</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>io.github.linpeilie</groupId>
                        <artifactId>mapstruct-plus-processor</artifactId>
                        <version>${mapstruct-plus.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

Specify Object Mapping Relationships

Add the @AutoMapper annotation to either User or UserDto and set targetType to the other class.

For example:

@AutoMapper(target = UserDto.class)
public class User {
    // ...
}

Testing

@SpringBootTest
public class QuickStartTest {

    @Autowired
    private Converter converter;

    @Test
    public void test() {
        User user = new User();
        user.setUsername("jack");
        user.setAge(23);
        user.setYoung(false);

        UserDto userDto = converter.convert(user, UserDto.class);
        System.out.println(userDto);    // UserDto{username='jack', age=23, young=false}

        assert user.getUsername().equals(userDto.getUsername());
        assert user.getAge() == userDto.getAge();
        assert user.isYoung() == userDto.isYoung();

        User newUser = converter.convert(userDto, User.class);

        System.out.println(newUser);    // User{username='jack', age=23, young=false}

        assert user.getUsername().equals(newUser.getUsername());
        assert user.getAge() == newUser.getAge();
        assert user.isYoung() == newUser.isYoung();
    }

}

Summary

After adding the dependency, using MapStruct Plus is very straightforward.

  • Add the AutoMapper annotation to the classes that need conversion.

  • Get the Converter instance and call the convert method.

#1
资源直链https://gitee.com/easii/mapstruct-plus
去下载
星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare