Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XStreamMarshaller + JsonHierarchicalStreamDriver + JsonWriter.DROP_ROOT_MODE produce empty output [SPR-6939] #11604

Closed
spring-projects-issues opened this issue Mar 3, 2010 · 3 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Yevhen Yaremchuk opened SPR-6939 and commented

When using XStreamMarshaller for serializing object to JSON by customizing StreamDriver to skip root node resulting in empty output. Configuration of StreamDriver illustrated by the following snapshot

final XStreamMarshaller marshaller = new XStreamMarshaller();

marshaller.setStreamDriver(new JsonHierarchicalStreamDriver() {
    public HierarchicalStreamWriter createWriter(Writer writer) {
        return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
    }
});

At the same time using XSTream directly works just fine.

final XStream xStream = new XStream(new JsonHierarchicalStreamDriver() {
    public HierarchicalStreamWriter createWriter(Writer writer) {
        return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
    }
});

Affects: 3.0 GA

Referenced from: commits ac9a625

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Can you indicate how you use the marshaller/xstream instance later on? Specifically: are you writing to a DOM tree, an OutputStream, a Writer, XMLStreamWriter, etc?

@spring-projects-issues
Copy link
Collaborator Author

Yevhen Yaremchuk commented

I used StringResult for testing. Item is simple bean with two properties (int id and String status)

final StringResult result = new StringResult();
final Item item = new Item(12, "new");
		
try {
        marshaller.getXStream().setMode(XStream.NO_REFERENCES);
        marshaller.getXStream().alias("item", Item.class);
	marshaller.marshal(item, result);
} catch (Exception e) {
// TODO: handle exception
}

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed.

@spring-projects-issues spring-projects-issues added type: bug A general bug in: data Issues in data modules (jdbc, orm, oxm, tx) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants