Class EnumConverter

  • All Implemented Interfaces:
    IConverter

    public class EnumConverter
    extends ScalarConverterBase
    An object to convert simple LinkML enums (excluding so-called “dynamic enums”, which are not yet supported).

    Similarly to the ObjectConverter, there should be one instance of this class for every type of enum that needs to be converted.

    This converter relies on the enum type providing (1) a fromString method that can be used to deserialise an enum value, and (2) a toString() method that can be used to serialise the value, in such a way that, if v is a value from the enum Enum, then Enum.fromString(v.toString()) == v is true.

    The Java code generator in LinkML-Py automatically produces such enum types, if the --true-enums option is used.

    • Constructor Detail

      • EnumConverter

        public EnumConverter​(Class<?> targetEnum)
                      throws LinkMLRuntimeException
        Creates a new converter for the specified type of enum.
        Parameters:
        targetEnum - The enum into which to convert raw objects.
        Throws:
        LinkMLRuntimeException - If the target type is not a valid enum type (either because it is not a Java enum to begin with, or because it does not provide the expected fromString method.