Class RelEnumTypes

  • public abstract class RelEnumTypes
    extends java.lang.Object
    Registry of Enum classes that can be serialized to JSON.

    Suppose you want to serialize the value SqlTrimFunction.Flag.LEADING to JSON. First, make sure that SqlTrimFunction.Flag is registered. The type will be serialized as "SYMBOL". The value will be serialized as the string "LEADING".

    When we deserialize, we rely on the fact that the registered enum classes have distinct values. Therefore, knowing that (type="SYMBOL", value="LEADING") we can convert the string "LEADING" to the enum Flag.LEADING.

    • Field Summary

      Modifier and Type Field Description
      private static<java.lang.String,​java.lang.Enum<?>> ENUM_BY_NAME  
    • Constructor Summary

      Modifier Constructor Description
      private RelEnumTypes()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String fromEnum​(java.lang.Enum enumValue)
      Converts an enum into its name.
      static java.lang.Object fromEnum​(java.lang.Object value)
      Converts a literal into a value that can be serialized to JSON.
      private static void register​(<java.lang.String,​java.lang.Enum<?>> builder, java.lang.Class<? extends java.lang.Enum> aClass)  
      (package private) static <E extends java.lang.Enum<E>>
      toEnum​(java.lang.String name)
      Converts a string to an enum value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENUM_BY_NAME

        private static final<java.lang.String,​java.lang.Enum<?>> ENUM_BY_NAME
    • Constructor Detail

      • RelEnumTypes

        private RelEnumTypes()
    • Method Detail

      • register

        private static void register​(<java.lang.String,​java.lang.Enum<?>> builder,
                                     java.lang.Class<? extends java.lang.Enum> aClass)
      • fromEnum

        public static java.lang.Object fromEnum​(java.lang.Object value)
        Converts a literal into a value that can be serialized to JSON. In particular, if is an enum, converts it to its name.
      • fromEnum

        public static java.lang.String fromEnum​(java.lang.Enum enumValue)
        Converts an enum into its name. Throws if the enum's class is not registered.
      • toEnum

        static <E extends java.lang.Enum<E>> E toEnum​(java.lang.String name)
        Converts a string to an enum value. The converse of fromEnum(Enum).