GithubHelp home page GithubHelp logo

mohanaraosv / mapstruct Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mapstruct/mapstruct

0.0 1.0 0.0 6.09 MB

An annotation processor for generating type-safe bean mappers

Home Page: http://mapstruct.org/

License: Other

Java 97.68% FreeMarker 2.32%

mapstruct's Introduction

MapStruct - Java bean mappings, the easy way!

Latest Stable Version Latest Version

What is MapStruct?

MapStruct is a Java annotation processor for the generation of type-safe bean mapping classes.

All you have to do is to define a mapper interface which declares any required mapping methods. During compilation, MapStruct will generate an implementation of this interface. This implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection or similar.

Compared to writing mapping code from hand, MapStruct saves time by generating code which is tedious and error-prone to write. Following a convention over configuration approach, MapStruct uses sensible defaults but steps out of your way when it comes to configuring or implementing special behavior.

Compared to dynamic mapping frameworks, MapStruct offers the following advantages:

  • Fast execution by using plain method invocations instead of reflection
  • Compile-time type safety: Only objects and attributes mapping to each other can be mapped, no accidental mapping of an order entity into a customer DTO etc.
  • Self-contained code, no runtime dependencies
  • Clear error-reports at build time, if entities or attributes can't be mapped
  • Mapping code is easy to debug (or edited by hand e.g. in case of a bug in the generator)

MapStruct works in command line builds (plain javac, via Maven, Gradle, Ant etc.) and IDEs. For Eclipse, there is a dedicated plug-in under development (see https://github.com/mapstruct/mapstruct-eclipse) which goes beyond what's possible with an annotation processor, providing content assist for annotation attributes, quick fixes and more.

Documentation and getting help

To learn more about MapStruct in two minutes, refer to the project homepage. The reference documentation covers all provided functionality in detail. If you need help, come and join the mapstruct-users group.

Requirements

MapStruct requires Java 1.6 or later.

Using MapStruct

MapStruct is a Java annotation processor based on JSR 269 and as such can be used within command line builds (javac, Ant, Maven etc.) as well as from within your IDE.

For Maven based projects add the following to your POM file in order to use MapStruct (the dependencies can be obtained from Maven Central):

...
<properties>
    <org.mapstruct.version>1.0.0.Final</org.mapstruct.version>
</properties>
...
<dependencies>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId> <!-- OR use this with Java 8 and beyond: <artifactId>mapstruct-jdk8</artifactId> -->
        <version>${org.mapstruct.version}</version>
    </dependency>
</dependencies>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.6</source> <!-- or 1.7 or 1.8, .. -->
                <target>1.6</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>
...

For Gradle, you need something along the following lines:

plugins {
    ...
    id 'net.ltgt.apt' version '0.8'
}
dependencies {
    ...
    compile 'org.mapstruct:mapstruct:1.0.0.Final' // OR use this with Java 8 and beyond: org.mapstruct:mapstruct-jdk8:...

    apt 'org.mapstruct:mapstruct-processor:1.0.0.Final'
}
...

Alternatively, a distribution bundle is available from SourceForge.

Licensing

MapStruct is licensed under the Apache License, Version 2.0 (the "License"); you may not use it except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Building from Source

MapStruct uses Maven for its build. To build the complete project run

mvn clean install

from the root of the project directory. To skip the distribution module, run

mvn clean install -DskipDistribution=true

Links

mapstruct's People

Contributors

agudian avatar bedla avatar chschu avatar cliedeman avatar dilipkrish avatar eforest avatar filiphr avatar ggtools avatar grandmasterpixel avatar greuelpirat avatar gunnarmorling avatar kryger avatar osthus-sm avatar pardom avatar pjlarson avatar ps-powa avatar seanjob avatar shasait avatar sjaakd avatar sonata82 avatar streetturtle avatar tisoft avatar vgtworld avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.