org.mapstruct.MappingTarget Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapstruct Show documentation
Show all versions of mapstruct Show documentation
An annotation processor for generating type-safe bean mappers
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Declares a parameter of a mapping method to be the target of the mapping.
*
* Not more than one parameter can be declared as {@code MappingTarget}.
*
* NOTE: The parameter passed as a mapping target must not be {@code null}.
*
*
* Example 1: Update exist bean without return value
*
*
* @Mapper
* public interface HumanMapper {
* void updateHuman(HumanDto humanDto, @MappingTarget Human human);
* }
*
*
* // generates
* @Override
* public void updateHuman(HumanDto humanDto, Human human) {
* human.setName( humanDto.getName() );
* // ...
* }
*
*
* Example 2: Update exist bean and return it
*
*
* @Mapper
* public interface HumanMapper {
* Human updateHuman(HumanDto humanDto, @MappingTarget Human human);
* }
*
* // generates:
*
* @Override
* public Human updateHuman(HumanDto humanDto, Human human) {
* // ...
* human.setName( humanDto.getName() );
* return human;
* }
*
*
*
* @author Andreas Gudian
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.CLASS)
public @interface MappingTarget {
}