Details
-
Type: Bug
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.2.2
-
Component/s: None
-
Labels:None
-
JDK version and platform:JDK 1.5
Description
If you are serializing objects that contain objects and the inner object has no non-null fields or primitive types, the close bracket is not emitted.
This test case
===
public void testSimpleTypesCanBeRepresentedAsJsonWithNullMembers() {
String expected = (
"{'innerMessage': {\n" +
" 'greeting': 'hello',\n" +
" 'innerMessage':
\n" +
"}}").replace('\'', '"');
XStream xs = new XStream(new JsonHierarchicalStreamDriver());
xs.alias("innerMessage", Msg.class);
Msg message = new Msg("hello");
Msg message2 = new Msg(null);
message.innerMessage = message2;
String xs_sgtr = xs.toXML(message);
assertEquals(expected, xs_sgtr);
}
public static class Msg
{
String greeting;
Msg innerMessage;
public Msg(String greeting)
}
===
Should produce
===
{"innerMessage": {
"greeting": "hello",
"innerMessage": {
}
}}
===
But instead produces
===
{"innerMessage": {
"greeting": "hello",
"innerMessage":
===
Hi Matthiew,
I've committed a fix for this. If it works for you, close this issue ...
Cheers,
Jörg