Serialization is simply converting the entity class to JSON.
Deserialization is converting json into the required entity class (data from background to foreground)
In deserialization, @serializedName can be used if the field name defined at the front and back ends is not the same
Some fields in the entity class that do not require data from the front end to the back end during serialization can be used with @expose
DataModel @SerializedName(“planno”), @SerializedName(value = “consid”) alternate = {“cons_id”})
@serializedname (value = “consid”, alternate = {“cons_id”})
2. Remove some fields from serialization as used in DataModel
The @expose (serialize = false) serialization setting false will remove this field
@expose () defaults to true to keep the field
Serialization methods note:
private String listToJson(List<DataModel> dataList) {
GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
Gson gson = builder.create();
String json = gson.toJson(dataList);
return json;
}Copy the code