Closed GoogleCodeExporter closed 9 years ago
I did not quite catch you.
Just uncomment the public modifier for BaseSomeBean to make it work.
SnakeYAML resides in another package then your code. That is why to be 'public'
is
important.
The fact that 'main' method is in the same package does give SnakeYAML parser
more privileges.
Original comment by py4fun@gmail.com
on 12 Feb 2010 at 5:43
Do you mean the error message is confusing ?
Original comment by py4fun@gmail.com
on 12 Feb 2010 at 5:47
Original comment by aso...@gmail.com
on 16 Feb 2010 at 6:52
The point is: there should be no exception at all - Snakeyaml should just be
able to
obtain the value of the "attribute1" property. Please take a look at any other
Java
serialization package, and see how they do this - I would suggest looking at
XStream
or Commons BeanUtils, which can successfully serialize this code.
Here is the alternate code using Commons BeanUtils, that you can try out:
public static void main(String[] args)
{
final SomeBean someBean = new SomeBeanImpl("value1", "value2");
final BeanMap beanMap = new BeanMap(someBean);
System.out.println(beanMap.values());
}
Original comment by sualeh.f...@gmail.com
on 17 Feb 2010 at 12:59
Original comment by aso...@gmail.com
on 17 Feb 2010 at 4:47
When I execute your example with BeanMap I get exactly the same error.
It does not throw an exception but it still cannot access the attribute:
WARN: Exception: java.lang.IllegalAccessException: Class
org.apache.commons.collections.BeanMap can not access a member of class
org.yaml.snakeyaml.issues.issue50.SnakeyamlTest$BaseSomeBean with modifiers
"public
final"
java.lang.IllegalAccessException: Class org.apache.commons.collections.BeanMap
can
not access a member of class
org.yaml.snakeyaml.issues.issue50.SnakeyamlTest$BaseSomeBean with modifiers
"public
final"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
at java.lang.reflect.Method.invoke(Method.java:607)
at org.apache.commons.collections.BeanMap.get(BeanMap.java:333)
at org.apache.commons.collections.BeanMap$10.next(BeanMap.java:485)
at org.apache.commons.collections.BeanMap.values(BeanMap.java:441)
at org.yaml.snakeyaml.issues.issue50.SnakeyamlTest.test2(SnakeyamlTest.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestR
eference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:197)
[class org.yaml.snakeyaml.issues.issue50.SnakeyamlTest$SomeBeanImpl, null,
value2]
Original comment by aso...@gmail.com
on 17 Feb 2010 at 8:08
Attachments:
I was mistaken about BeanUtils. Please could you also test with XStream, with
this
code:
pom.xml
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
</dependency>
SnakeyamlTest.java
public void test3() throws IOException {
final StringWriter writer = new StringWriter();
final XStream xstream = new XStream();
xstream.toXML(someBean, writer);
System.out.println(writer);
}
Original comment by sualeh.f...@gmail.com
on 20 Feb 2010 at 6:21
http://joe.truemesh.com/blog//000479.html
Original comment by sualeh.f...@gmail.com
on 24 Feb 2010 at 8:10
It looks like a problem in Eclipse.
This test fails in Eclipse but works if you run it with Maven:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue50/SnakeyamlTest.java
Try: mvn clean test
Original comment by aso...@gmail.com
on 1 Mar 2010 at 2:25
It looks like it is JDK (or compiler ?) specific.
Fails with:
- Eclipse compiler
- OpenJDK 1.6, Ubuntu
- Sun JDK 1.5, Ubuntu
Works with:
- Sun JDK 1.6, Windows
- Sun JDK 1.6, Ubuntu
Any information is mush appreciated.
Original comment by aso...@gmail.com
on 1 Mar 2010 at 6:03
XStream works with the Eclipse compiler, for me. It seems that there is some
version
specific functionality in XStream - http://xstream.codehaus.org/faq.html
Basically, I wanted to ask if you could consider using XStream as the engine
for
your serialization. XStream already has two JSON "hierarchical stream drivers",
and
it would be great to have a YAML hierarchical stream driver as well.
Original comment by sualeh.f...@gmail.com
on 2 Mar 2010 at 12:53
Using XStream as the engine for the serialization is a major change for
SnakeYAML.
Since this is the only reported issue and it is _very_ specific I do not think
it is
worth to implement.
The other way around - implementing YAML "hierarchical stream driver" for
XStream may
be useful for those who use YAML only in Java. XStream is very Java-centric. It
assumes that you can always change the Java class to achieve the result. But
the YAML
document may be generated or expected to be consumed in another language.
XStream use
annotations, 'transient' modifier, explicit Java class names etc.
Original comment by aso...@gmail.com
on 2 Mar 2010 at 12:10
[deleted comment]
Another approach - would this help?
java.lang.reflect.AccessibleObject.setAccessible(boolean)
Original comment by sualeh.f...@gmail.com
on 2 Mar 2010 at 1:31
Thank you very much !!!
It is fixed. Check the latest source.
I have tested the fix with different JDKs. It works.
It will be released in version 1.7
Original comment by aso...@gmail.com
on 2 Mar 2010 at 3:27
Original issue reported on code.google.com by
sualeh.f...@gmail.com
on 12 Feb 2010 at 4:04