I know that when a class implements the serializable
interface then the serialization on a java object will be done, this object will be become series of bytes. If an app communicates with a Webservice in Json
format by using OkHttp, Gson
. why does this app that has certain class have to implement the serializable
interface?
Asked
Active
Viewed 128 times
0

duy hoang
- 59
- 8
1 Answers
0
You are getting this wrong!
OkHttp, Gson
does not need class to be serialized. But if you want to pass that model (Bean or Pojo what you say) to Bundle. Then you have to make it Serializable
.
Like you have class A. And you want pass this to next activity.
A model = new A();
Intent i = new Intent(MainActivity.this, ReceiverActivity.class);
i.putExtra("modelA", model);
In ReceiverActivity
onCreate() you write
Model model = (Model) getIntent().getSerializableExtra("modelA");
If you don't extend Serializable
to your class then you can not use this method even.
By the way you should use Parcelable instead of Serializable. That will make your model class lengthy but its performance is better than Serializable. See this answer for implementation.

Khemraj Sharma
- 57,232
- 27
- 203
- 212