I am trying to transmit objects of a particular class from one server to another.
The options I'm looking at are:
What are the best practices in this area? What are the gotchas?
Ideally I would like the interface to be versioned, so the sender and receiver can be upgraded independently.
I'm considering the JSON approach as I already have code that will serialize/deserialize the objects into JSON.
Whenever I needed to transmit Java objects, assuming similar JVM versions, I always used plain Java serialization (Sun official tutorial): it's simpler and you don't have to care about transmit chains of items or aggregates because serialization already cares about it (if you implement it correctly).
So if you want to transmit a complex object made by many sub-objects you don't have to split it, send it and recompose it: you just send the object and it already contains everything that was already included.
EDIT
About RMI: I used it together with serialization and it worked like a charm! I used to develop remote swing (sending JPanels over TCP)..
Of course I don't know what exactly you want to do but both tools work great and can also be used orthogonally.
If both ends are written in Java, just use Java's own serialization.
On the other hand, using JSON, XML or YAML will make it easier to debug as what gets transmitted will be readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With