in pulsar-client-reactive-jackson/src/main/java/org/apache/pulsar/reactive/client/jackson/ConverterUtils.java [46:77]
static <T> T toClass(ClassConf conf) {
if (conf == null) {
return null;
}
Class<?> klass;
try {
klass = loadClass(conf.getClassName(), Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException ex) {
throw new RuntimeException(String.format("Failed to load class %s", conf.getClassName()));
}
try {
if (conf.getArgs() != null) {
Constructor<?> ctor = klass.getConstructor(Map.class);
return (T) ctor.newInstance(conf.getArgs());
}
else {
Constructor<?> ctor = klass.getConstructor();
return (T) ctor.newInstance();
}
}
catch (NoSuchMethodException ex) {
throw new RuntimeException(
String.format("Class %s does not have a no-arg constructor or a constructor that accepts map",
klass.getName()),
ex);
}
catch (IllegalAccessException | InstantiationException | InvocationTargetException ex) {
throw new RuntimeException(String.format("Failed to create instance for %s", klass.getName()), ex);
}
}