Skip to content

yasasbanukaofficial/mini-model-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Mini Model Mapper

Maven Central License Java Version

Mini Model Mapper is a high-efficiency, zero-dependency Java library designed for modern developers who need fast object-to-object mapping without the bloat of traditional frameworks.


✨ Key Features

  • 🚀 High Performance: Optimized reflection-based mapping with meta-data caching for near-native speed.
  • 📦 Zero Dependencies: Keeps your project lightweight and avoids dependency hell.
  • Java 21 Ready: Fully compatible with the latest LTS features.
  • 🛠️ Simple Model Mapping: Single-line mapping for DTOs, Entities, and POJOs.

📦 Installation

Add the following dependency to your pom.xml, refer the mvnrepository for the latest version:

<dependency>
    <groupId>io.github.yasasbanukaofficial</groupId>
    <artifactId>mini-model-mapper</artifactId>
    <version>1.0.2</version>
</dependency>

🚀 Usage

1. Spring Boot Integration (Recommended)

Define the mapper as a Bean in your configuration or main application class:

@SpringBootApplication
public class BackendApplication {
    @Bean
    public MiniModelMapper miniModelMapper() {
        return new MiniModelMapper();
    }
}

Inject it into your service and map objects with a single line:

@Service
public class UserService {
    @Autowired
    private MiniModelMapper mapper;

    public UserResponseDTO createUser(UserRequestDTO request) {
        // Map DTO to Entity
        UserEntity user = mapper.map(request, UserEntity.class);
        
        // ... save to database ...
        
        return mapper.map(user, UserResponseDTO.class);
    }
}

2. Standard Java Usage

For non-Spring projects, simply create an instance. The mapper uses internal caching, so it is recommended to reuse a single instance (Singleton).

MiniModelMapper mapper = new MiniModelMapper();

Source source = new Source("John Doe", 25);
Destination destination = mapper.map(source, Destination.class);

💡 Pro-Tips for Complex Objects

Mini Model Mapper is designed to be safe and efficient. To avoid infinite recursion (circular dependencies) and "LazyInitializationExceptions" in JPA, the mapper automatically skips Collections and Maps.

Handle nested collections using Java Streams:

OrderDTO orderDTO = mapper.map(orderEntity, OrderDTO.class);

// Manually map nested collections to maintain control and safety
orderDTO.setItems(
    orderEntity.getItems().stream()
               .map(item -> mapper.map(item, ItemDTO.class))
               .toList()
);

🛠️ Requirements

  • Java 21 or higher.
  • Objects must have a no-args constructor (can be private/protected).

About

High-Performance Object Mapping Engine. Reflection-optimized metadata caching for zero-dependency DTO orchestration. Engineered for Java 21+ with minimal memory overhead and atomic field synchronization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages