JBotSim icon indicating copy to clipboard operation
JBotSim copied to clipboard

Serializing versus overriding toString()

Open acasteigts opened this issue 5 years ago • 2 comments

When a node overrides toString() and the topology is exported (serialized), the content returned by toString() is used in the format and the file cannot be re-imported afterwards. This is true, at least, for the plain format.

We should probably use the node ID instead of the content returned by toString() in the exportation.

acasteigts avatar Jan 31 '20 10:01 acasteigts

I agree with the fact that there is something to be improved here. I had a similar issue with the PlainTopologySerializer and a toString() with a "[ID] bar" pattern.

Beyond simply using the node ID, which is not necessarily unique, a more flexible mechanism could be provided. For example, without having thought too much about this, something like overriding a String onSerialize() or a String onSerialize(Serializer) method might help. The default behavior would be to return the String value of getID().

remikey avatar Jan 31 '20 13:01 remikey

For now, I suggest adopt the default behavior that your mention: returning the String value of getID(). I agree that an additional layer of abstraction might help in some cases, but the use of non-unique identifiers is pretty rare. For now, I don't think the need deserves complexifying the API.

acasteigts avatar Jan 31 '20 14:01 acasteigts