How to hide bean type in snakeyaml
Use org.yaml.snakeyaml.representer.Representer
, set Tag.MAP
to hide the root tag.
Representer representer = new Representer();
representer.addClassTag(Person.class, Tag.MAP);
You can extend Representer to 'sneakily' inject any non-registered bean class as Map.
public class MapRepresenter extends Representer {
@Override
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
if (!classTags.containsKey(javaBean.getClass()))
addClassTag(javaBean.getClass(), Tag.MAP);
return super.representJavaBean(properties, javaBean);
}
}