作者:手机用户2502928693 | 来源:互联网 | 2023-09-17 18:28
您可以传递自定义PropertyUtils来处理此类情况
Constructor c = new Constructor(MyClass.class);
c.setPropertyUtils(new PropertyUtils() {
@Override
public Property getProperty(Class extends Object> type, String name) throws IntrospectionException {
if ( name.indexOf('-') > -1 ) {
name = toCameCase(name);
}
return super.getProperty(type, name);
}
});
Yaml yaml = new Yaml(c);
MyClass obj = (MyClass) yaml.load(input);