MikeB
MikeB

Reputation: 257

Using Parceler library with Serialization

I want to use Parceler library with Serialization. This is what I have now without using this library:

public class Venue {

@SerializedName("id")
String venueID;
@SerializedName("name")
String venueName;
@SerializedName("url")
String venueUrl;


public Venue() {
}}

I read the library's tutorial and it says that I can just use it by adding the annotation:

@Parcel(Parcel.Serialization.BEAN)

But I still confused. As I understood I don't need to use @SerializedName annotation. So do I need to use my fields with it's original name or with there serialized name? Like this:

    @Parcel(Parcel.Serialization.BEAN)
    public class Venue {

        //    @SerializedName("id")
        String id;
        //    @SerializedName("name")
        String name;
        //    @SerializedName("url")
        String url;

@ParcelConstructor
    public Venue(String id, String name, String url) {
        this.id = id;
        this.name = name;
        this.url = url;

    }

        public Venue() {
        }

    }

Or this:

    @Parcel(Parcel.Serialization.BEAN)
    public class Venue {
        //    @SerializedName("id")
        String vnueID;
        //    @SerializedName("name")
        String venueName;
        //    @SerializedName("url")
        String venueUrl;

@ParcelConstructor
        public Venue(String vnueID, String venueName, String venueUrl) {
            this.vnueID = vnueID;
            this.venueName = venueName;
            this.venueUrl = venueUrl;

        }

        public Venue() {
        }

    }

Sorry if this is dumb question, but I don't yet understand parseable and serialization yet.

Upvotes: 0

Views: 744

Answers (1)

John Ericksen
John Ericksen

Reputation: 11113

Using Parcel.Serialization.BEAN will direct Parceler to look for and use getters and setters in accordance with the Java Bean standard. Your case calls for the default FIELD strategy which will access your Venue fields directly. Parceler does not use the @SerializedName annotation.

This should be a reasonable configuration of your Venue class:

@Parcel
public class Venue {
    String venueID;
    String venueName;
    String venueUrl;
}

Upvotes: 1

Related Questions