Class EnumWriteSupport<E extends Enum<E>>

java.lang.Object
org.springframework.data.r2dbc.convert.EnumWriteSupport<E>
Type Parameters:
E - the enum type that should be written using the actual value.
All Implemented Interfaces:
org.springframework.core.convert.converter.Converter<E,E>

@WritingConverter public abstract class EnumWriteSupport<E extends Enum<E>> extends Object implements org.springframework.core.convert.converter.Converter<E,E>
Support class to natively write Enum values to the database.

By default, Spring Data converts enum values by to String for maximum portability. Registering a WritingConverter allows retaining the enum type so that actual enum values get passed thru to the driver.

Enum types that should be written using their actual enum value to the database should require a converter for type pinning. Extend this class as the CustomConversions support inspects Converter generics to identify conversion rules.

For example:

 enum Color {
        Grey, Blue
 }

 class ColorConverter extends EnumWriteSupport<Color> {

 }
 
Since:
1.2
Author:
Mark Paluch
  • Constructor Details

    • EnumWriteSupport

      public EnumWriteSupport()
  • Method Details

    • convert

      public E convert(E enumInstance)
      Specified by:
      convert in interface org.springframework.core.convert.converter.Converter<E extends Enum<E>,E extends Enum<E>>