ldh0826 / snakeyaml

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

JavaBean Property set bug #134

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.my domain is:
public class Kv{

        private String mKey ; 

        private String mValue ;

        public String getmKey() {
            return mKey;
        }
        public void setmKey(String mKey) {
            this.mKey = mKey;
        }
        public String getmValue() {
            return mValue;
        }
        public void setmValue(String mValue) {
            this.mValue = mValue;
        }
} 

2.and yaml is:
insert: !!com.hqb360.analysis.analyser.domain.entity.Kv
  mKey: 1
  mValue: 1

3.then has error:
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 
'mKey' on class: com.hqb360.analysis.analyser.domain.entity.Kv
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:342)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:240)
    ... 40 more
4: when I modify it my domain like this:
public class MKeyValue {
        private String key ;
        private String value ;

        public String getKey() {
            return key;
        }
        public void setKey(String key) {
            this.key = key;
        }
        public String getValue() {
            return value;
        }
        public void setValue(String value) {
            this.value = value;
        } 
} 
and yaml is :
insert: !!com.hqb360.analysis.analyser.domain.entity.Kv
  key: 1
  value: 1

then is no error.

What is the expected output? What do you see instead?
JavaBean property liek "MKey" can not be read by snakeyaml , I want to know why?

What version of SnakeYAML are you using? On what Java version?
1.9

Please provide any additional information below. (Often a failing test is
the best way to describe the problem.)

Exception is :
Caused by: Can't construct a java object for 
tag:yaml.org,2002:com.hqb360.analysis.analyser.domain.entity.Kv; 
exception=Cannot create property=mKey for 
JavaBean=com.hqb360.analysis.analyser.domain.entity.Kv@3cb075; Unable to find 
property 'mKey' on class: com.hqb360.analysis.analyser.domain.entity.Kv
 in "<reader>", line 1, column 9:
    insert: !!com.hqb360.analysis.analyser.d ... 
            ^

    at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:372)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:177)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:280)
    at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:124)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:261)
    at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:442)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:177)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:136)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:122)
    at org.yaml.snakeyaml.Loader.load(Loader.java:52)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:166)
    at com.hqb360.test.base.AbstractSpringDaoTest.getYamlData(AbstractSpringDaoTest.java:37)
    ... 27 more
Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot create property=mKey 
for JavaBean=com.hqb360.analysis.analyser.domain.entity.Kv@3cb075; Unable to 
find property 'mKey' on class: com.hqb360.analysis.analyser.domain.entity.Kv
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:305)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:184)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:370)
    ... 38 more
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 
'mKey' on class: com.hqb360.analysis.analyser.domain.entity.Kv
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:342)
    at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:240)
    ... 40 more

Original issue reported on code.google.com by longt...@gmail.com on 21 Oct 2011 at 8:20

GoogleCodeExporter commented 9 years ago
The names of the properties in the first case do not conform to the JavaBean 
specification. The first letter after 'set' or 'get' must be in upper case.

setmValue -> setMValue

Original comment by py4fun@gmail.com on 21 Oct 2011 at 2:48

GoogleCodeExporter commented 9 years ago
my domain is :
1.my domain is:
public class Kv{

        private String mKey ; 

        private String mValue ;

        public String getMKey() {
            return mKey;
        }
        public void setMKey(String mKey) {
            this.mKey = mKey;
        }
        public String getMValue() {
            return mValue;
        }
        public void setMValue(String mValue) {
            this.mValue = mValue;
        }
} 
I make mistake from CTRL + V when I use "key" way, it still has error in 1.9

Original comment by longt...@gmail.com on 25 Oct 2011 at 6:19

GoogleCodeExporter commented 9 years ago
domain like this:
public class Kv{

        private String mKey ; 

        private String mValue ;

        public String getmKey() {
            return mKey;
        }
        public void setmKey(String mKey) {
            this.mKey = mKey;
        }
        public String getmValue() {
            return mValue;
        }
        public void setmValue(String mValue) {
            this.mValue = mValue;
        }
} 

has no error!

Original comment by longt...@gmail.com on 25 Oct 2011 at 6:36

GoogleCodeExporter commented 9 years ago
I did not quite catch the message. Does it work ? If it does not, can you 
please send a failing JUnit test ?

Original comment by py4fun@gmail.com on 25 Oct 2011 at 7:41

GoogleCodeExporter commented 9 years ago
JavaBean specification is define that . when property's second character is 
uppercase,then the first character after "get" method should be lowercase.also 
in "set" method.
eg: 
private String iMac;
public String getiMac(){
...
}
public void setiMac(String iMac){
...
}

so it is no error in snakeyaml , it's my fault. thank you very much!

Original comment by longt...@gmail.com on 26 Oct 2011 at 3:53

GoogleCodeExporter commented 9 years ago

Original comment by py4fun@gmail.com on 26 Oct 2011 at 7:36