TypeDescription.substituteProperty doesn't substitute

Issue #403 open
Dustin Spicuzza created an issue

I would expect substituteProperty to replace the existing property, but getProperties returns two properties. Am I misunderstanding the purpose of this method? Thanks!

Java 8, SnakeYAML 1.20

import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.introspector.PropertySubstitute;
import org.yaml.snakeyaml.representer.Representer;

import java.util.Set;

public class SubstDemo {

    class MyThing {

        String prop;

        public String getProp() {
            return prop;

        public void setProp(String prop) {
            this.prop = prop;

    public static void main(String [] args) {

        TypeDescription td = new TypeDescription(MyThing.class);
        Constructor c = new Constructor();
        Representer r = new Representer();


        td.substituteProperty(new PropertySubstitute("prop", Integer.class));

        Set<Property> props = td.getProperties();
        if (props.size() == 1) {
        } else {
            System.out.println("FAIL " + props.size());


PS: Thanks for SnakeYAML, it's very useful!

Comments (3)

  1. Alexander Maslov

    I am afraid at the moment PropertySubstitute is not really a substitute (or at least not yet that powerful as you want it to be).

    It will serve as a substitute if name and type are the same as existing property. In all other cases it is more like adding ArtificialProperty.

    PropertySubstitute idea needs more love and care... :) We will see if it is achievable.

  2. Log in to comment