|
[
Permalink
| « Hide
]
Dan Diephouse added a comment - 27/Apr/07 08:21 AM
Any chance you can submit tests/code that show this behavior using Jettison directly instead of XStream?
yes:
public static void main(String[] args) { A a =new A(); A b =new A(); A[] array=new A[]{a}; XStream xstream=new XStream(new JettisonDriver()); System.out.println(xstream.toXML(array)); A[] array2=new A[]{a,b}; xstream=new XStream(new DomDriver()); System.out.println(xstream.toXML(array)); System.out.println(xstream.toXML(array2)); } The above test also compares what is returned by the DomDriver. I think you missed my point - Can you show this bug using just the org.codehaus.jettison.* classes? i.e. MappedXMLStreamWriter?
Sorry for misunderstanding you.
JettionsDriver.createWriter methods are implemented as following: where mof is an instance of MappedXMLOutputFactory. <-- Jettison class. public HierarchicalStreamWriter createWriter(Writer writer) { Thanks -John Hi Dan,
I've investigated in this and the unit test below shows what XStream is calling: {format:java}public void testIssue22() throws XMLStreamException, IOException { StringWriter strWriter = new StringWriter(); MappedNamespaceConvention con = new MappedNamespaceConvention(); AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter); w.writeStartDocument(); w.writeStartElement("", "array-a", ""); w.writeStartElement("", "a", ""); w.writeStartElement("", "n", ""); w.writeCharacters("1"); w.writeEndElement(); w.writeEndElement(); /* w.writeStartElement("", "a", ""); w.writeStartElement("", "n", ""); w.writeCharacters("2"); w.writeEndElement(); w.writeEndElement(); */ w.writeEndElement(); w.writeEndDocument(); w.close(); strWriter.close(); System.out.println(strWriter.toString()); assertEquals("{\"array-a\":{\"a\":[{\"n\":\"1\"}]}}", strWriter.toString()); }{format} It boils down to the question, how can the MappedXMLStreamWriter be forced to write an array containing a single element?
Since the JIRA formatting went wrong, here's the code as diff.
fixed by adding a a special seriliazeAsArray() method that could be used to force appropriate serialization. See the following use case for example. In order to make XStream support this, the driver should be changed, which I will do after the release
public void testSingleArrayElement() throws Exception { w.writeStartDocument(); w.writeStartElement("", "a", ""); w.writeEndElement(); w.close(); System.out.println(strWriter.toString()); assertEquals("{\"array-a\":{\"a\":[{\"n\":1}]}}", strWriter.toString()); |
|||||||||||||||||||||||||||||||||||||||||||||||||||