All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapstruct.Named Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
/*
 * 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;

/**
 * Marks mapping methods with the given qualifier name. Can be used to qualify a single method or all methods of a given
 * type by specifying this annotation on the type level.
 * 

* Will be used to select the correct mapping methods when mapping a bean property type, element of an iterable type * or the key/value of a map type. *

* Example (both methods of {@code Titles} are capable to convert a string, but the ambiguity is resolved by applying * the qualifiers in {@code @Mapping}: * *

 * 
 * @Named("TitleTranslator")
 * public class Titles {
 *
 *   @Named("EnglishToGerman")
 *   public String translateTitleEG(String title) {
 *       // some mapping logic
 *   }
 *
 *   @Named("GermanToEnglish")
 *   public String translateTitleGE(String title) {
 *       // some mapping logic
 *   }
 * }
 *
 * @Mapper( uses = Titles.class )
 * public interface MovieMapper {
 *
 *    @Mapping( target = "title", qualifiedByName = { "TitleTranslator", "EnglishToGerman" } )
 *    GermanRelease toGerman( OriginalRelease movies );
 *
 * }
 * 
 * 
* * The following implementation of {@code MovieMapper} will be generated: * *
 * 
 *
 * public class MovieMapperImpl implements MovieMapper {
 *     private final Titles titles = new Titles();
 *
 *     @Override
 *     public GermanRelease toGerman(OriginalRelease movies) {
 *         if ( movies == null ) {
 *             return null;
 *         }
 *
 *         GermanRelease germanRelease = new GermanRelease();
 *
 *         germanRelease.setTitle( titles.translateTitleEG( movies.getTitle() ) );
 *
 *         return germanRelease;
 *     }
 * }
 * 
 * 
* * @author Sjaak Derksen * @see org.mapstruct.Mapping#qualifiedByName() * @see IterableMapping#qualifiedByName() * @see MapMapping#keyQualifiedByName() * @see MapMapping#valueQualifiedByName() */ @Target( { ElementType.TYPE, ElementType.METHOD } ) @Retention( RetentionPolicy.CLASS ) @Qualifier public @interface Named { /** * A name qualifying the annotated element * * @return the name. */ String value(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy