content: package com.example.xxljobexp.utils;
  
  import sun.reflect.ReflectionFactory;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Field;
  
  public class SerializeUtils {
      public static Object createWithoutConstructor(String classname) throws Exception {
          return createWithoutConstructor(Class.forName(classname));
      }
      public static <T> T createWithoutConstructor(Class<T> classToInstantiate) throws Exception {
          return createWithConstructor(classToInstantiate, Object.class, new Class[0], new Object[0]);
      }
      public static <T> T createWithConstructor(Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes, Object[] consArgs) throws Exception {
          Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes);
          objCons.setAccessible(true);
          Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(classToInstantiate, objCons);
          sc.setAccessible(true);
          return (T) sc.newInstance(consArgs);
      }
      public static void setFieldValue(final Object obj, final String fieldName, final Object value) throws Exception {
          final Field field = getField(obj.getClass(), fieldName);
          field.setAccessible(true);
          if(field != null) {
              field.set(obj, value);
          }
      }
      public static Field getField(final Class<?> clazz, final String fieldName) {
          Field field = null;
          try {
              field = clazz.getDeclaredField(fieldName);
              field.setAccessible(true);
          } catch (NoSuchFieldException ex) {
              if (clazz.getSuperclass() != null)
                  field = getField(clazz.getSuperclass(), fieldName);
          }
          return field;
      }
  }
  