EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Default Conversions and Converters/Converter
From Eclipsepedia
< EclipseLink | UserGuide | JPA | Basic JPA Development | Mapping | Basic Mappings | Default Conversions and Converters
EclipseLink JPA
| EclipseLink |
| Website |
| Download |
| Community |
| Mailing List • Forums • IRC |
| Bugzilla |
| Open |
| Help Wanted |
| Bug Day |
| Contribute |
| Browse Source |
@Converter
You can use @Converter annotation to specify a custom converter for modification of the data value(s) during the reading and writing of a mapped attribute.
@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface Converter { String name(); Class converterClass(); }
| Attribute | Description | Default | Required? |
|---|---|---|---|
| name | Set this attribute to the String name for your converter. Ensure that this name is unique across the persistence unit | Yes | |
| converterClass | Set this attribute to the Class of your converter. This class must implement the EclipseLink org.eclipse.persistence.mappings.converters.Converter interface. | Yes |
The following example shows how to use the @Converter annotation to specify Employee field gender.
Example: @Converter Annotation
@Entity public class Employee implements Serializable{ ... @Basic @Converter ( name="genderConverter", converterClass=org.myorg.converters.GenderConverter.class ) @Convert("genderConverter") public String getGender() { return gender; } ... }