Search code examples
androidserializationretrofitparcelablepojo

@SerializedName("home") is it invalid annotation in order to implement parcelable


I am using Retrofit and have many pojo class according to json. Since I am Using Gson parsing I need to use:

@SerializedName("home")
private List<Home> home = new ArrayList<>();

@SerializedName("away")
private List<Away> Away= new ArrayList<>();

public List<Home> getHome() {
  return home;
}

Now I want to implement Parcelable in all pojo class.

I am not very sure will @serialized name annotation use java serialization or just a name check annotation?

Will it add any runtime exceptions while unmarshalling in parcel?


Solution

  • There's no problem with SerializedName and Parcelable.

    SerializedName is a GSON annotation for specifying JSON property names and has really nothing to do with Java serialization.

    When you implement Parcelable, you write the marshal/unmarshal code yourself (or generate it yourself) and no reflection or annotation lookup needs to happen at runtime.