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

org.mapstruct.ValueMapping Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
/**
 *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
 *  and/or other contributors as indicated by the @authors tag. See the
 *  copyright.txt file in the distribution for a full listing of all
 *  contributors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.mapstruct;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Configures the mapping of source constant value to target constant value.
 * 

* Supported mappings are *

    *
  1. Enumeration to Enumeration
  2. *
*

* Example 1: * *

 * 
 * public enum OrderType { RETAIL, B2B, EXTRA, STANDARD, NORMAL }
 *
 * public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT }
 *
 * @ValueMapping(source = "EXTRA", target = "SPECIAL"),
 * @ValueMapping(source = "STANDARD", target = "DEFAULT"),
 * @ValueMapping(source = "NORMAL", target = "DEFAULT")
 * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
 * 
 * Mapping result:
 * +---------------------+----------------------------+
 * | OrderType           | ExternalOrderType          |
 * +---------------------+----------------------------+
 * | null                | null                       |
 * | OrderType.EXTRA     | ExternalOrderType.SPECIAL  |
 * | OrderType.STANDARD  | ExternalOrderType.DEFAULT  |
 * | OrderType.NORMAL    | ExternalOrderType.DEFAULT  |
 * | OrderType.RETAIL    | ExternalOrderType.RETAIL   |
 * | OrderType.B2B       | ExternalOrderType.B2B      |
 * +---------------------+----------------------------+
 * 
* * MapStruct will WARN on incomplete mappings. However, if for some reason no match is found an * {@link java.lang.IllegalStateException} will be thrown. *

* Example 2: * *

 * 
 * @ValueMapping( source = "<NULL>", target = "DEFAULT" ),
 * @ValueMapping( source = "STANDARD", target = "<NULL>" ),
 * @ValueMapping( source = "<ANY_REMAINING>", target = "SPECIAL" )
 * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
 * 
 * Mapping result:
 * +---------------------+----------------------------+
 * | OrderType           | ExternalOrderType          |
 * +---------------------+----------------------------+
 * | null                | ExternalOrderType.DEFAULT  |
 * | OrderType.STANDARD  | null                       |
 * | OrderType.RETAIL    | ExternalOrderType.RETAIL   |
 * | OrderType.B2B       | ExternalOrderType.B2B      |
 * | OrderType.NORMAL    | ExternalOrderType.SPECIAL  |
 * | OrderType.EXTRA     | ExternalOrderType.SPECIAL  |
 * +---------------------+----------------------------+
 * 
* * @author Sjaak Derksen */ @Repeatable(ValueMappings.class) @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface ValueMapping { /** * The source value constant to use for this mapping. * *

* Valid values: *

    *
  1. enum constant name
  2. *
  3. {@link MappingConstants#NULL}
  4. *
  5. {@link MappingConstants#ANY_REMAINING}
  6. *
  7. {@link MappingConstants#ANY_UNMAPPED}
  8. *
*

* NOTE:When using <ANY_REMAINING>, MapStruct will perform the normal name based mapping, in which * source is mapped to target based on enum identifier equality. Using <ANY_UNMAPPED> will not apply name * based mapping. * * @return The source value. */ String source(); /** * The target value constant to use for this mapping. * *

* Valid values: *

    *
  1. enum constant name
  2. *
  3. {@link MappingConstants#NULL}
  4. *
* * @return The target value. */ String target(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy