Hello. I configure the client to communicate with the server through serialization.

I have a wrapper class in which I put the name of the class and the method I need to call on the server. before being sent to the server, it is serialized, well, and there, respectively, it is deserialized.

The question is:

Some methods on the server should return me some objects. For example, an object of class User . On the server lies, suppose, a jar file from which the server finds out about such a class. How does the client know about this class?

After all, I understand that the wrong approach would be to duplicate two files on this client and server with this class?

Then, if this class changes on the server, will an error be generated during serialization / deserialization? Or not?

    1 answer 1

    By experience, I will say that for this you do not need to use serialization, because as you already guessed, you will have to duplicate fields and classes and even directories in the project. Better use JSON or xml . The first rewrites java objects into a javascript object, and the second reworks in xml and sends as a string. The most simple, popular and convenient ways.

    • Clear. But if the List <User> should come to me from the server in Json format. On the client, I convert Json back to List <User>. Well, where should I get the User class from? Same problem like? - andreyatake
    • I created a class with the necessary fields on the client for this purpose in order to transfer json there and already from this class quietly receive all the fields that are needed. In general, you will need to write a User miniclass with everything you need (username, password, message, date for example) - Ula La
    • Well thank you. As I understand it, if I get the List <User> server in Json format, in order to convert it normally into what I need, I have to create a User class on the client with the same fields as User’s on the server? - andreyatake
    • Yes, but not necessarily. If you want, you can process json yourself as a regular line and get all the necessary information, but it looks like a crutch + there will be bugs, the perfect line will not always be sent by the user, and you cannot take everything into account, unlike library solutions - Ula La