Parceler Arg Converter usage

Marcin Moskała edited this page Apr 30, 2017 · 1 revision

To use Parceler converter there must be used at least version 0.60. There also must be added dependency with converter. Example gradle dependencies:

compile 'com.github.marcinmoskala.activitystarter:activitystarter:0.60-beta.1'
apt 'com.github.marcinmoskala.activitystarter:activitystarter-compiler:0.60-beta.1'
compile 'com.github.MarcinMoskala.ActivityStarter:activitystarter-parceler-arg-converter:0.60-beta.1'

Converter must be added on lib configuration annotation:

@ActivityStarterConfig(converters = { ParcelarArgConverter.class })

This annotation can be placed on any class, but it is suggested to place it behind BaseActivity. Do not define more than one ActivityStarterConfig! It is one for the whole project. [Example].(https://github.com/MarcinMoskala/ActivityStarter/blob/master/sample/app/src/main/java/com/example/activitystarter/BaseActivity.java)

While there is class or interface that are all objects that are used as Parcel's extending or implementing, this could lead to problems when there would be more than one not implementing anything object types to convert. This is why where was interface created to mark all objects that can be wrapped and unwrapped by Parcel. This interface is IsParcel. All objects that we would like to pass as an argument wrapped and unwrapped by Parceler should implement it:

@org.parceler.Parcel
public class StudentParceler implements IsParcel {

    private int id;
    private String name;
    private char grade;

    public StudentParceler() {
    }

//...
}

Whole object here.

When the converter is registered in configurations then we can use isParcel objects like any other defined types:

@Arg StudentParceler student;