Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Not A Bug
-
Affects Version/s: 1.3.1
-
Fix Version/s: None
-
Component/s: IO
-
Labels:None
-
JDK version and platform:sun jdk 1.6_21
Description
Context:
I was trying to map an attribute in an xml file (with no namespace) to a field in an object using spring batch integration with Xtream
I use the @XStreamAsAttribute annotation
It works if I launch xstream directly (it use the xpp parser)
It doesn't work if I launch xstream throught spring batch integration because it use stax parser.
Why:
The spring batch integration is done using spring XstreamMarshaller that use xstream StaxReader
The stax parser validate that attribute match namespace, see org.springframework.xml.stream.AbstractXmlStreamReader ligne 152
When trying to fetch an attribute StaxReader.getAttribute(String name) is called with a null namespace
return in.getAttributeValue(null, name);
=> always return null when used with the stax parser.
Solution:
In the StaxReader class replace
return in.getAttributeValue(null, name);
with
return in.getAttributeValue("", name);
Note:
I was able to override the StaxReader and the XStreamMarshaller class and configure and overrided XStreamMarshaller in spring to make it work
May I site the Javadoc of the StAX API for XMLStreamReader.getAttributeValue():
Actually, if I apply your change, XStream has failing unit tests when accessing attributes of XML without namespace.
Maybe Spring should adjust their implementation to conform the specification?