
| Key: |
XSTR-371
|
| Type: |
Bug
|
| Status: |
Closed
|
| Resolution: |
Fixed
|
| Assignee: |
Unassigned
|
| Reporter: |
J. Matthew Pryor
|
| Votes: |
0
|
| Watchers: |
1
|
|
If you were logged in you would be able to see more operations.
|
|
|
XStream
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
|
|
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": {
}}
===
|
|
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" +
" }\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": {
}}
=== |
Show » |
|
I've committed a fix for this. If it works for you, close this issue ...
Cheers,
Jörg