Class EnumTransform<T extends Enum<T>>

java.lang.Object
de.xima.fc.converter.simple.EnumTransform<T>
Type Parameters:
T - Type of the enum class.
All Implemented Interfaces:
org.simpleframework.xml.transform.Transform<T>

public class EnumTransform<T extends Enum<T>> extends Object implements org.simpleframework.xml.transform.Transform<T>
Transformer similar to for enums which allows you to specify how unknown enum constants are handled.
Author:
XIMA MEDIA GmbH
  • Constructor Details

    • EnumTransform

      public EnumTransform(Class<T> enumClass)
      An enum transformer that uses the strategyThrow() strategy.
      Parameters:
      enumClass - Class of the enum type.
    • EnumTransform

      public EnumTransform(Class<T> enumClass, BiFunction<Class<T>,String,T> unknownEnumStrategy)
      An enum transformer that uses the specified strategy for handling unknown enums.
      Parameters:
      enumClass - Class of the enum type.
      unknownEnumStrategy - Strategy for resolving unknown enums. It is passed the enum class and the serialized string.
  • Method Details

    • read

      public T read(String value) throws Exception
      Specified by:
      read in interface org.simpleframework.xml.transform.Transform<T extends Enum<T>>
      Throws:
      Exception
    • write

      public String write(T value) throws Exception
      Specified by:
      write in interface org.simpleframework.xml.transform.Transform<T extends Enum<T>>
      Throws:
      Exception
    • strategyNull

      public static <T extends Enum<T>> BiFunction<Class<T>,String,T> strategyNull()
      Returns:
      A strategy that, if the enum constant does not exist, substitutes null.
    • strategyThrow

      public static <T extends Enum<T>> BiFunction<Class<T>,String,T> strategyThrow()
      Returns:
      A strategy that, if the enum constant does not exist, throws an IllegalArgumentException.