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

XStream and JavaFX Observable Collection Classes #14

Open
MichaelEllis opened this issue Jun 18, 2015 · 4 comments
Open

XStream and JavaFX Observable Collection Classes #14

MichaelEllis opened this issue Jun 18, 2015 · 4 comments

Comments

@MichaelEllis
Copy link

I am trying to use XStream to Internalize/Externalize some classes that rely on JavaFX Properties and JavaFX Observable collections.

I have been using XStreamFX but have run into a problem with the deserialisation for ObservableListWrapper which seems to fail due is not having a no argument constructor.

I have reported the problem as an XStreamFX Issue but am wondering if XStream will add support for these commonly used FX data classes?

@joehni
Copy link
Member

joehni commented Jun 18, 2015

I was not aware of XStreamFX at all and you're actually the first asking for JavaFX support here at XStream. However, there's currently no one here who knows JavaFX for real. So, yes, in principle it wold be possible to create a new xstream artifact with JavaFX support, but the code must be donated with proper license and valid unit tests (that's how xstream-hibernate came into existence).

XStreamFX's ObservableListConverter is flawed, because it assumes it can handle any type implementing the ObservableList interface. A similar situation exists for XStream handling Collection types and XStream's CollectionConverter does not handle on purpose arbitrary Collection types (see #10). You will need an own converter for ObjectListWrapper.

@MichaelEllis
Copy link
Author

@joehni Thanks for the reply. I have experimented with creating my own ObservableListConverter as follows

public class ObservableListConverter extends CollectionConverter implements Converter {

    public ObservableListConverter(Mapper mapper) {
        super(mapper);
    }

    @Override
    public boolean canConvert(Class type) {
        return ObservableList.class.isAssignableFrom(type);
    }

    @Override
    protected Object createCollection(Class type) {
        if (type == ObservableListWrapper.class) {
            return FXCollections.<Person>observableArrayList();
        }
        return super.createCollection(type);
    }
}

And this works so long as the collection is not implicit i.e. annotated with @XStreamImplicit. Can you offer any advice as how I could handle @XStreamImplicit?

@joehni
Copy link
Member

joehni commented Jun 21, 2015

Have you read about it in the FAQ?

@LiSongMWO
Copy link

+1 I would also like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants