假设您必须删除所有出现的!!int
您可以查看How to skip a property to skip the property or do some transformation using Flexible Scalar Type Customization
简而言之,您配置Yaml
实例如下
Yaml yaml = new Yaml(new MyRepresenter());
String output = yaml.dump(new MyJavaBean());
其中 MyRepresenter 表示如下
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
Object propertyValue, Tag customTag) {
if (int.class.equals(property.getType())) {//some better condition
//construct NodeTupe as you wish - i.e. keep the element and remove the type
return null;//this will skip the property
} else {
return super
.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
}