@Retention(value=CLASS) @Target(value=METHOD) public @interface ValueMapping
Supported mappings are
Example 1:
public enum OrderType { RETAIL, B2B, EXTRA, STANDARD, NORMAL }
public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT }
@ValueMappings({
@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
IllegalStateException
will be thrown.
Example 2:
@ValueMappings({
@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 |
+---------------------+----------------------------+
public abstract String source
Valid values:
MappingConstants.NULL
MappingConstants.ANY_REMAINING
MappingConstants.ANY_UNMAPPED
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.
public abstract String target
Valid values:
MappingConstants.NULL
Copyright © 2012-2016 Gunnar Morling; All rights reserved. Released under the Apache Software License 2.0.