Thinkofname / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
1 stars 0 forks source link

Cannot create property bug for subclass add set method for property #193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

import org.yaml.snakeyaml.Yaml;

public class TestYaml {

    public static abstract class BeanA {

       public abstract Object getId();

    }

    public static class BeanA1 extends BeanA {

        private Long id;

       // @Override
        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }

    public static void main(String[] args) {

        System.out.println("test...");
        BeanA1 b = new BeanA1();
       b.setId(2l);
       b.setName("name1");
       Yaml yaml = new Yaml();
        String dump = yaml.dump(b);

       System.out.println("dump:"+dump);

       yaml.load(dump);

       dump = "!!scripts.spring.TestYaml$BeanA1 {id: 2, name: name1}";

       yaml.load(dump); //BUG:Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find propert
    }
}

Original issue reported on code.google.com by qxodr...@gmail.com on 3 Jun 2014 at 8:26

GoogleCodeExporter commented 9 years ago
What does the 'dump' variable contain before the re-assignment ?

Original comment by py4fun@gmail.com on 3 Jun 2014 at 1:00

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The provided code works as expected.

Original comment by py4fun@gmail.com on 4 Jun 2014 at 6:26

GoogleCodeExporter commented 9 years ago

why the exception is ok ?  

Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'id' 
on class: TestYaml$BeanA1

import org.yaml.snakeyaml.Yaml;

public class TestYaml {

    public static abstract class BeanA {

       public abstract Object getId();

    }

    public static class BeanA1 extends BeanA {

        private Long id;

         public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }

    public static void main(String[] args) {

        System.out.println("test...");
        BeanA1 b = new BeanA1();
       b.setId(2l);
       b.setName("name1");
       Yaml yaml = new Yaml();
        String dump = yaml.dump(b);

       System.out.println("dump:"+dump);

       yaml.load(dump);

       dump = "!!TestYaml$BeanA1 {id: 2, name: name1}"; //BUG : Unable to find property 'id' on class: TestYaml$BeanA1

       yaml.load(dump);
    }
}

Original comment by qxodr...@gmail.com on 5 Jun 2014 at 2:06

GoogleCodeExporter commented 9 years ago
1) the code you have given works without exceptions
2) please read the question above and give the answer - what is the contents of 
the 'dump' variable before it has been re-assigned
3) what is the SnakeYAML version ?
4) what is the Java version ?
5) to show that your code works without exceptions, tests have been added:
https://code.google.com/p/snakeyaml/source/list

You can see the code here:
https://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeya
ml/issues/issue193/TestYaml.java

Feel free to take the source code and change it in a way it fails.

Original comment by py4fun@gmail.com on 5 Jun 2014 at 8:11

GoogleCodeExporter commented 9 years ago
It's jvm problem:(

test SnakeYAML version(1.12 and 1.13)

on oracle(sun) jvm (jdk1.6.0_45) not work,but on oracle jvm(1.7,1.8) work
fine

on IBM jvm 1.5:build pwi32devifx-20100127 (SR11 FP1 ) not work,but on IBM
jvm 1.6 work fine

2014-06-05 16:11 GMT+08:00 <snakeyaml@googlecode.com>:

Original comment by qxodr...@gmail.com on 6 Jun 2014 at 3:41

GoogleCodeExporter commented 9 years ago
Well, Oracle JVM 1.6 is supported. 
I will try to reproduce the issue.

Original comment by py4fun@gmail.com on 6 Jun 2014 at 4:56

GoogleCodeExporter commented 9 years ago
Apple 1.6.0_43 ... _60 fails as well.

I think this in related to https://bugs.openjdk.java.net/browse/JDK-6794807 
which is duplicates https://bugs.openjdk.java.net/browse/JDK-6528714 which was 
not back-ported to Java 6.

I am not even sure we can fix it.

At the moment you can use BeanAccess.FIELD if you you can accept direct field 
access for all SnakeYAML processed classes (ignoring setters and getters) :

{{{
Yaml yaml = new Yaml();
yaml.setBeanAccess(BeanAccess.FIELD);
}}}

or you can use BeanAccess.FIELD only for some classes :

{{{
Constructor c = new Constructor();
Representer r = new Representer();

PropertyUtils pu = new PropertyUtils();
c.setPropertyUtils(pu);
r.setPropertyUtils(pu);

pu.getProperties(BeanA1.class, BeanAccess.FIELD);

Yaml yaml = new Yaml(c, r);
}}}

If you need even more control on Bean's properties, you can try my clone. But 
at the moment it is a bit out of sync with the master and not yet finalized ;)

Original comment by alexande...@gmail.com on 6 Jun 2014 at 7:53

GoogleCodeExporter commented 9 years ago
Alex, since you have the best picture of the problem feel free to contribute.
(you may also close it with "WontFix" given the detailed description)

Original comment by py4fun@gmail.com on 6 Jun 2014 at 8:21

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
WontFix: see comment 8

Original comment by alexande...@gmail.com on 29 Aug 2014 at 12:11