Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Default Conversions and Converters/Converter"

From Eclipsepedia

Jump to: navigation, search
m (@Converter)
m (@Converter)
Line 1: Line 1:
=@Converter and <converter>=
|1=*[http://www.eclipse.org/eclipselink/api/latest org.eclipse.persistence.mappings.converters.Converter]}}
|1=*[http://www.eclipse.org/eclipselink/api/latest org.eclipse.persistence.mappings.converters.Converter]}}

Revision as of 15:12, 17 June 2010

@Converter and <converter>

Elug api package icon.png Key API {{{apis}}}

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.

 public @interface Converter {
    String name();
    Class converterClass(); 
@Converter Attributes
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

This example shows how to use the @Converter annotation to specify Employee field gender.

Usage of the @Converter Annotation

 public class Employee implements Serializable{
     @Converter (
     public String getGender() {
         return gender;

Version: 2.1.0
Other versions...