fix issue 50: Unable to dump JavaBean that inherits from a protected base class
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 49812e6..cf2d1a6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -7,9 +7,8 @@
</properties>
<body>
<release version="1.7" date="in Mercurial" description="development">
- <action dev="py4fun" type="update">
- Issue 50 is connected to problems reported in issue 1. Introspector.getBeanInfo()
- does not work as expected. Latest Sun JDKs work properly (2010-03-01)
+ <action dev="py4fun" type="fix" issue="50" due-to="sualeh.fatehi">
+ Unable to dump JavaBean that inherits from a protected base class (2010-03-02)
</action>
<action dev="py4fun" type="update">
Format source (2010-03-01)
diff --git a/src/main/java/org/yaml/snakeyaml/introspector/MethodProperty.java b/src/main/java/org/yaml/snakeyaml/introspector/MethodProperty.java
index bdd4cb1..b2cd78a 100644
--- a/src/main/java/org/yaml/snakeyaml/introspector/MethodProperty.java
+++ b/src/main/java/org/yaml/snakeyaml/introspector/MethodProperty.java
@@ -57,6 +57,7 @@
@Override
public Object get(Object object) {
try {
+ property.getReadMethod().setAccessible(true);// issue 50
return property.getReadMethod().invoke(object);
} catch (Exception e) {
throw new YAMLException("Unable to find getter for property '" + property.getName()
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue50/SnakeyamlTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue50/SnakeyamlTest.java
index f7f4350..d268aa8 100644
--- a/src/test/java/org/yaml/snakeyaml/issues/issue50/SnakeyamlTest.java
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue50/SnakeyamlTest.java
@@ -15,8 +15,6 @@
*/
package org.yaml.snakeyaml.issues.issue50;
-import java.util.Properties;
-
import junit.framework.TestCase;
import org.yaml.snakeyaml.Yaml;
@@ -68,21 +66,10 @@
public void testIntrospector() throws Exception {
SomeBean someBean = new SomeBeanImpl("value1", "value2");
Yaml dumper = new Yaml();
- try {
- String output = dumper.dump(someBean);
- // System.out.println(output);
- assertEquals(
- "!!org.yaml.snakeyaml.issues.issue50.SnakeyamlTest$SomeBeanImpl {attribute1: value1,\n attribute2: value2}\n",
- output);
- } catch (Exception e) {
- System.out
- .println("Unexpected result. Check issue 50. http://code.google.com/p/snakeyaml/issues/detail?id=50");
- Properties props = System.getProperties();
- for (Object key : new String[] { "java.runtime.name", "java.vm.version",
- "java.vm.vendor", "java.vm.name", "java.runtime.version", "os.version",
- "java.specification.version", "java.version" }) {
- System.out.println(key.toString() + ": " + props.getProperty(key.toString()));
- }
- }
+ String output = dumper.dump(someBean);
+ // System.out.println(output);
+ assertEquals(
+ "!!org.yaml.snakeyaml.issues.issue50.SnakeyamlTest$SomeBeanImpl {attribute1: value1,\n attribute2: value2}\n",
+ output);
}
}