com.opensymphony.xwork2.conversion.annotations

## Annotation Type TypeConversion

-     @Target(value=METHOD)
       @Retention(value=RUNTIME)
      public @interface TypeConversion

  This annotation is used for class and application wide conversion rules.

  Class wide conversion:
  The conversion rules will be assembled in a file called `XXXAction-conversion.properties` within the same package as the related action class. Set type to: `type = ConversionType.CLASS`

  Application wide conversion:
  The conversion rules will be assembled within the `xwork-conversion.properties` file within the classpath root. Set type to: `type = ConversionType.APPLICATION`

  Annotation usage:

  The TypeConversion annotation can be applied at property and method level.

  Annotation parameters:

  Parameter | Required | Default | Description
  --- | --- | --- | ---
  key | no | The annotated property/key name | The optional property name mostly used within TYPE level annotations.
  type | no | ConversionType.CLASS | Enum value of ConversionType. Determines whether the conversion should be applied at application or class level.
  rule | no | ConversionRule.PROPERTY | Enum value of ConversionRule. The ConversionRule can be a property, a Collection or a Map.
  converter | either this or value |  | The class or bean name of the TypeConverter to be used as converter.
  converterClass | either this or value | XWorkBasicConverter | The class of the TypeConverter to be used as converter.
  value | either converter or this |  | The value to set for ConversionRule.KEY_PROPERTY.

  Example code:

       @Conversion()
       public class ConversionAction implements Action {

         private String convertInt;

         private String convertDouble;
         private List users = null;

         private HashMap keyValues = null;

         @TypeConversion(type = ConversionType.APPLICATION)
         public void setConvertInt( String convertInt ) {
             this.convertInt = convertInt;
         }

         @TypeConversion(converterClass = XWorkBasicConverter.class)
         public void setConvertDouble( String convertDouble ) {
             this.convertDouble = convertDouble;
         }

         @TypeConversion(rule = ConversionRule.COLLECTION, converterClass = String.class)
         public void setUsers( List users ) {
             this.users = users;
         }

         @TypeConversion(rule = ConversionRule.MAP, converterClass = BigInteger.class)
         public void setKeyValues( HashMap keyValues ) {
             this.keyValues = keyValues;
         }

         @TypeConversion(type = ConversionType.APPLICATION, property = "java.util.Date", converterClass = XWorkBasicConverter.class)
         public String execute() throws Exception {
             return SUCCESS;
         }
       }

  Version:
    $Id$
  Author:
    Rainer Hermanns

- - ### Optional Element Summary

    Optional Elements
    Modifier and Type | Optional Element and Description
    --- | ---
    `String` | `converter` The class or bean name of the TypeConverter to be used as converter.
    `Class<?>` | `converterClass` The class of the TypeConverter to be used as converter.
    `String` | `key` The optional key name used within TYPE level annotations.
    `ConversionRule` | `rule` The ConversionRule can be a PROPERTY, KEY, KEY_PROPERTY, ELEMENT, COLLECTION (deprecated) or a MAP.
    `ConversionType` | `type` The ConversionType can be either APPLICATION or CLASS.
    `String` | `value` If used with ConversionRule.KEY_PROPERTY specify a value here! Note: If you use ConversionType.APPLICATION, you can not set a value!

- - ### Element Detail

    - #### key

          public abstract String key

      The optional key name used within TYPE level annotations. Defaults to the property name.
      Returns:
        key
      Default:
        ""

  - - #### type

          public abstract ConversionType type

      The ConversionType can be either APPLICATION or CLASS. Defaults to CLASS. Note: If you use ConversionType.APPLICATION, you can not set a value!
      Returns:
        the conversion type
      Default:
        com.opensymphony.xwork2.conversion.annotations.ConversionType.CLASS

  - - #### rule

          public abstract ConversionRule rule

      The ConversionRule can be a PROPERTY, KEY, KEY_PROPERTY, ELEMENT, COLLECTION (deprecated) or a MAP. Note: Collection and Map conversion rules can be determined via com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer.
      Returns:
        the conversion rule
      See Also:
        `DefaultObjectTypeDeterminer`
      Default:
        com.opensymphony.xwork2.conversion.annotations.ConversionRule.PROPERTY

  - - #### converter

          public abstract String converter

      The class or bean name of the TypeConverter to be used as converter. Note: This can not be used with ConversionRule.KEY_PROPERTY!
      Returns:
        class or bean name of the TypeConverter to be used as converter
      See Also:
        `#converterClass()}`
      Default:
        ""

  - - #### converterClass

          public abstract Class<?> converterClass

      The class of the TypeConverter to be used as converter. Note: This can not be used with ConversionRule.KEY_PROPERTY!
      Returns:
        class of the TypeConverter to be used as converter
      Default:
        com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.class

  - - #### value

          public abstract String value

      If used with ConversionRule.KEY_PROPERTY specify a value here! Note: If you use ConversionType.APPLICATION, you can not set a value!
      Returns:
        value
      Default:
        ""

Copyright © 2000–2023 Apache Software Foundation. All rights reserved.