I need to implement serializable for the model class while using gson (serialization / deserialization Library)

I use the default httpurlconnection class to make API calls, and use gson to convert Java objects into JSON requests and JSON responses into equivalent Java objects. I have created various models (POJO classes) to convert requests / responses into model objects. Because gson is a serialization / deserialization library, is it ideal to serialize all these models?

public class Contact implements Serializable {
    private String name;
    private String email;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}

I removed serializable tools from all models. Everything seems to be normal, but I'm confused about whether it's correct?

resolvent:

It depends on what you want to do with them, but most likely not. Serializability is a way to serialize data in Java, similar to the default Java method. JSON serialization is another. Parallel is one-third of Android. The only thing you need to use serializable is, Do you want to pass it to the API that takes serializable as a parameter? If you don't need to do so, you can serialize it with gson instead of serializable

The difference between the three methods lies in the data format they output to. Different formats have their own advantages and disadvantages, but they can complete the work

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>