Upon attempting to enable DnD for my app and passing around an object that encapsulates a RosterEntry, I noticed that it is not Serializable. Any reason that this is the case? It adds another workaround that I have to do…
If we were to mark any classes in Smack as Serializable, I’'d like to figure out all the ones that should be marked as such and apply the change in a consistent way across the whole API. Do you have any recommendations on what classes should be Serializable to kick things off?
Well, I only ran into one specific case where it was a problem. I had RosterGroup encapsulated in a class that extends DefaultMutableTreeNode, the same for RosterEntry, and I have instrumented drag and drop on my tree of contacts so that you can drag items in the tree, for instance: drag a contact to a HostedRoom. I did have my nodes implement Transferable so that all the data in the node would be available on drop. This is so that I could remove the node if the action was to move a contact to a new group. Anyway, for me, if any object you can get from a Roster was Serializable, that would have solved that. I just made TreePath my Transferable and get the node from the path and all. Not sure if there are any other cases where it would benefit…
I looked at the code and unfortunately it doesn’'t seem like an easy fix to make RosterEntry or RosterGroup serializable since they take use XMPPConnection as a private variable.
Maybe a good longer-term solution would be for us to provide some Swing helper classes to assist with these types of situations?
What I would reccomend, as it is what I have done, is create a class to wrap in the DefaultMutableTreeNode that contains the information you want. An example of what is relevant to a contact list would be, alias, user id, and presence info. Not to much else is particularly relevant. You can then make that class serializable and deal with it in the context of the current connection.
Hope that helps,