我创建了一个名为Configuration.java的自定义类,我希望将它放入我的Storm拓扑中的Config对象中。当我尝试拓扑时,我不断收到错误:
java.lang.IllegalArgumentException: Topology conf is not json-serializable
这是我的代码,它试图将Configuration对象放入Config
public static Config loadConf(String resource) {
Configuration _epconf = null;
Yaml yaml = new Yaml();
Config conf = new Config();
conf.registerSerialization(Configuration.class); //register the Configuration class
try {
//load the yaml file into the Configuration pojo
_epconf = (Configuration)yaml.loadAs(new InputStreamReader(new FileInputStream(resource)), Configuration.class);
} catch (FileNotFoundException e) {
Log.error("Configuration file does not exist : " + resource);
System.err.println("Conf file does not exist : " + resource);
System.exit(-1);
} catch (YAMLException e ) {
Log.error("Error parsing YAML file for configuration : " + resource + "\n" + e.getMessage());
System.err.println("Error parsing YAML file for configuration : " + resource);
System.exit(-1);
}
//verify object is not empty
if (_epconf == null) {
Log.error("Empty configuration object created from : " + resource );
System.err.println("Empty configuration object created from : " + resource);
System.exit(-1);
}
conf.put("epconf", _epconf); //add the Configuration to the Config object
return conf;
}
我认为问题在于我没有正确注册我的班级进行序列化。我怀疑conf.registerSerialization(Configuration.class)并不完全正确,但是我无法理解风暴主页上的文档要求的内容。