Class ClassHelper


  • public class ClassHelper
    extends Object
    Helper methods for handling classes
    • Constructor Detail

      • ClassHelper

        public ClassHelper()
    • Method Detail

      • convert

        public static <T> T convert​(Object object,
                                    Class<T> type)
        Converts a bean, handling both getters / setters and public fields
      • describe

        public static Map<String,​Object> describe​(Object object)
        Reads all properties and public fields from the given object, returning an empty map for null input
      • fill

        public static void fill​(Object object,
                                Map<String,​Object> values)
        Sets each property / public field in the map, ignoring errors
      • instantiate

        public static <T> T instantiate​(Class<T> type)
        Instantiates a bean of the given class, using the default constructor
        Throws:
        IllegalStateException - When there was a checked exception (used as cause)
      • instantiate

        public static <T> T instantiate​(Class<T> type,
                                        Supplier<T> supplier)
        Instantiates a bean of the given class, using the default constructor or from the given supplier if an instantiate error occurs
      • instantiateDynamic

        public static <T,​D extends T> T instantiateDynamic​(Class<T> expectedType,
                                                                 String classProperty,
                                                                 Class<D> defaultType)
                                                          throws Exception
        Instantiates a class, reading the class name from the environment, then a system property, then using a default type
        Throws:
        Exception