Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Not A Bug
-
Affects Version/s: 1.3.1
-
Fix Version/s: None
-
Component/s: Converters
-
Labels:None
Description
The attached unit test outputs:
json={"com.thoughtworks.xstream.io.json.Foo":{"list":"","childs":[""]},"bar":["bar"]} before Foo: bar [] [] after Foo: null [] [] junit.framework.AssertionFailedError: expected:<Foo: bar [] []> but was:<Foo: null [] []> at com.thoughtworks.xstream.io.json.EmptyElementsTest.testEmptyArray(EmptyElementsTest.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
As you can see the first array list is serialised as an empty string, the second is serialized as an array of empty strings, and bar is serialized as an array with a string in it.
If you move the declaration of bar above the two lists in Foo.class, the test will pass, however the json produced is still suspicious.
I suspect the issue is caused by the json writer being confused about its path, similar to what happened in http://jira.codehaus.org/browse/XSTR-640
Please use Jettison 1.2. Note, that this version will still create a JSONArray with an empty string as single element for an empty list or array, but it will not produce this garbage anymore.