xstream
xstream copied to clipboard
XStream and JavaFX Observable Collection Classes
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?
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.
@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?
Have you read about it in the FAQ?
+1 I would also like this.