When parsing my XML files with Simple, I get errors like the following one:
org.simpleframework.xml.core.ValueRequiredException:
Unable to satisfy ... on field 'id' private String Foo.id
for class Foo at line -1
What do I need to change to get the real line number?
[EDIT] Here is a Gist: Demo for SimpleXml l开发者_如何学JAVAine number problem
I'm using simple-xml:2.6.1 and junit:4.9
Depends on where it is run. If you run in JDK 1.5, witout StAX in the classpath this means you are using DOM, so you will always get -1 on an error. If you use JDK 1.5 or above with StAX in the classpath then StAX does not support line numbers (perhaps try a different lib, I recomment Woodstox).
[EDIT] If you want to try Woodstox and you use Maven, add this to your POM:
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>3.1.1</version>
</dependency>
This is the version which uses Apache License 2.0. If you prefer LGPL 2.1, replace -asl
with -lgpl
.
精彩评论