Issue Type: Bug Bug
Affects Versions: 1.4.4, 1.4.3, 1.4.1, 1.4
Assignee: Jörg Schaible
Components: Compatibility, Converters
Created: 12/Mar/13 2:07 PM
Description:

I was in the midst of upgrading Xstream 1.3 to 1.4. However I am finding that the JSON generated is incorrect, and I am not sure what I need to do resolve this. I wrote a JUNIT test and was able to reproduce the problem. Here's the code for the test

public class XstreamTest {

<at> Test
public void testXstreamStuffForBasicVO()

{ BasicVO basicVO = new BasicVO("atttr1", "attr2"); XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); //XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.registerConverter(new BasicVOConverter()); System.out.println(xstream.toXML(basicVO)); //return setupXstream(xstream); }

class BasicVO{
<at> XStreamAlias("alias1")
private String attribute1;

<at> XStreamAlias("alias2")
private String attribute2;

BasicVO(String att1, String att2)

{ setAttribute1(att1); setAttribute2(att2); }

BasicVO(){

}

public String getAttribute1()

{ return attribute1; }

public void setAttribute1(String attribute1)

{ this.attribute1 = attribute1; }

public String getAttribute2()

{ return this.attribute2; }

public String getAttribute3()

{ return "madeupAttribute"; }

public void setAttribute2(String attribute2)

{ this.attribute2 = attribute2; }

}

class BasicVOConverter implements Converter{

<at> Override
public boolean canConvert(Class type)

{ return BasicVO.class.isAssignableFrom(type); }

<at> Override
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context)

{ BasicVO basicVO = (BasicVO) source; writer.startNode("property1"); writer.setValue(basicVO.getAttribute1()); writer.endNode(); writer.startNode("property2"); writer.setValue(basicVO.getAttribute2()); writer.endNode(); writer.startNode("property3"); writer.setValue(basicVO.getAttribute3()); writer.endNode(); }

<at> Override
public Object unmarshal(HierarchicalStreamReader reader,
UnmarshallingContext context)

{ BasicVO basicVO = new BasicVO(); reader.moveDown(); basicVO.setAttribute1(reader.getValue()); reader.moveUp(); reader.moveDown(); basicVO.setAttribute2(reader.getValue()); reader.moveUp(); return person; }

}
}

The output generated is the following invalid JSON( invalid because the values are not within double quotes )

{"com.xyz.XstreamTest$BasicVO": {
"property1": atttr1,
"property2": attr2,
"property3": madeupAttribute
}}

I would like to point out that, when I use JettisonMappedXmlDriver, this isn't a problem, however, I cannot use this, since I loose some other important things which I get with JsonHierarchicalStreamDriver.

With Xstream 1.3, I get the following

{"com.xyz.XstreamTest$BasicVO": {
"property1": "atttr1",
"property2": "attr2",
"property3": "madeupAttribute"
}}

I went through the Xstream 1.4 and 1.3 code and found significant differences in the logic for applying double quotes In 1.3, quotes are added more generally. However in 1.4, quotes are only added for a "String" type, which I am not sure how this gets determined, but I suspect, this might be causing this bug.

I am inclining towards maybe some bug in xstream 1.4 code? This seems too far fetched, I am probably missing some step.

Project: XStream
Priority: Major Major
Reporter: Mohammad Meah
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to