Search code examples
javaxstream

Can XStream handle complex objects without any extra work?


I'm thinking of using the XStream library but I have a couple of questions/concerns.

Say I have a complex object that I want to serialize into XML (or JSON) using XStream. Is XStream able to handle this without any extra work?

For example:

class Foo
{
    private Bar bar;
    private string name;

    // Getters and Setters
}


class Bar
{
    private Integer id;
    private string name;

    // getters and setters
}

Can XStream handle this correctly? Thanks!


Solution

  • Short answer: Yes, it can.

    But will do it with a lot of reflection overhead. I wouldn't write such code in production release. Also, keep in mind that you have to look for bi-directional reference which will cause a runtime exception.