Search code examples
androidlombokparceler

Parceler and Lombok not working together?


For my android app I use the parceler library and the lombok library.

These are the annotations of my class:

@Table
@ToString
@Getter
@NoArgsConstructor
@Parcel
public class MyClass {

However, during gradle build, Parceler complains that there is no default empty constructor. So does this mean it doesn't recognize the @NoArgsConstructor annotation and these two simply won't work together? Because e.g. SugarORM has no probs with it. Or am I just missing something?


Solution

  • This gets into how Lombok adds code to your class. Lombok uses a known trick in the Java annotation processor to add code to your class. This added code is not visible to Parceler during the annotation processor round and makes the added no-args constructor unknown to Parceler.

    I'd recommend adding the no-args constructor manually, annotating the existing constructor with @ParcelConstructor (I assume you have one) or consider using the Lombok fork Hrisey that has an @Parcelable annotation.

    We had an issue/question about this recently: https://github.com/johncarl81/parceler/issues/177