History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-371
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Unassigned
Reporter: J. Matthew Pryor
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XStream

JSON writer generates malformed output when inner content has null fields

Created: 21/Dec/06 06:50 AM   Updated: 24/May/07 12:38 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.2

JDK version and platform: JDK 1.5


 Description  « Hide
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" +
" }\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) {
this.greeting = greeting;
}
}
===
Should produce
===
{"innerMessage": {
  "greeting": "hello",
  "innerMessage": {
  }
}}
===
But instead produces
===
{"innerMessage": {
  "greeting": "hello",
  "innerMessage": {
}}
===

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 01/Jan/07 12:06 PM
Hi Matthiew,

I've committed a fix for this. If it works for you, close this issue ...

Cheers,
Jörg

J. Matthew Pryor - 05/Mar/07 05:27 AM
Sorry for the delayed response, yes this works nicely