Class EnumUuidConverters.StringToEnum

java.lang.Object
su.onno.spring.EnumUuidConverters.StringToEnum
All Implemented Interfaces:
org.springframework.core.convert.converter.GenericConverter
Enclosing class:
EnumUuidConverters

@ReadingConverter public static final class EnumUuidConverters.StringToEnum extends Object implements org.springframework.core.convert.converter.GenericConverter
Reads a framework enum back from a varchar column that holds the enum's UUID as text.

EnumUuidConverters.UuidToEnum only fires when the JDBC value comes back as a UUID, which requires the column to be typed uuid. When an attribute changed from String to an @Enumeration on a database whose column was already provisioned as varchar, onno keeps writing the enum's UUID but the driver hands it back as a String. Without this converter Spring Data falls through to Enum.valueOf(<uuid string>) and throws IllegalArgumentException: No enum constant ... (issue #168).

The value must be a UUID and is resolved through EnumerationPersistence. Legacy enum-name values must be converted with the 2.0 migration tool before this reader runs.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.core.convert.converter.GenericConverter

    org.springframework.core.convert.converter.GenericConverter.ConvertiblePair
  • Method Summary

    Modifier and Type
    Method
    Description
    convert(Object source, org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType)
     
    Set<org.springframework.core.convert.converter.GenericConverter.ConvertiblePair>
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getConvertibleTypes

      public Set<org.springframework.core.convert.converter.GenericConverter.ConvertiblePair> getConvertibleTypes()
      Specified by:
      getConvertibleTypes in interface org.springframework.core.convert.converter.GenericConverter
    • convert

      @Nullable public Object convert(@Nullable Object source, org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType)
      Specified by:
      convert in interface org.springframework.core.convert.converter.GenericConverter