Package org.objenesis

Class ObjenesisHelper

java.lang.Object
org.objenesis.ObjenesisHelper

public final class ObjenesisHelper extends Object
Use Objenesis in a static way. It is strongly not recommended to use this class.
  • Field Details

    • OBJENESIS_STD

      private static final Objenesis OBJENESIS_STD
    • OBJENESIS_SERIALIZER

      private static final Objenesis OBJENESIS_SERIALIZER
  • Constructor Details

    • ObjenesisHelper

      private ObjenesisHelper()
  • Method Details

    • newInstance

      public static <T> T newInstance(Class<T> clazz)
      Will create a new object without any constructor being called
      Type Parameters:
      T - Type instantiated
      Parameters:
      clazz - Class to instantiate
      Returns:
      New instance of clazz
    • newSerializableInstance

      public static <T extends Serializable> T newSerializableInstance(Class<T> clazz)
      Will create an object just like it's done by ObjectInputStream.readObject (the default constructor of the first non serializable class will be called)
      Type Parameters:
      T - Type instantiated
      Parameters:
      clazz - Class to instantiate
      Returns:
      New instance of clazz
    • getInstantiatorOf

      public static <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz)
      Will pick the best instantiator for the provided class. If you need to create a lot of instances from the same class, it is way more efficient to create them from the same ObjectInstantiator than calling newInstance(Class).
      Type Parameters:
      T - Type to instantiate
      Parameters:
      clazz - Class to instantiate
      Returns:
      Instantiator dedicated to the class
    • getSerializableObjectInstantiatorOf

      public static <T extends Serializable> ObjectInstantiator<T> getSerializableObjectInstantiatorOf(Class<T> clazz)
      Same as getInstantiatorOf(Class) but providing an instantiator emulating ObjectInputStream.readObject behavior.
      Type Parameters:
      T - Type to instantiate
      Parameters:
      clazz - Class to instantiate
      Returns:
      Instantiator dedicated to the class
      See Also: