last modified: 2-jul-2017 (23:31)
YABK (Yet Another Boilerplate Killer) is an annotation processor for generating mutators/accessor and parcelable implementation of java POJOs.
For the applications which depend heavily on WEB APIs, we have to model network responses and in Android sometimes we need to make them Parcel too.
A lot of these models, doesn’t contain any logic but methods for accessing or setting fields. Generating these fields or parcelables every time we have to update the model is cumbersome.
YABK addresses this issue and generates accessor/mutators and parcelable implementation of models at compile time.
For processing any POJO with Yabk
, add @YabkProcess
annotation on required class.
Yabk generated class for above example
Class must be abstract
Class must have a non-private no-arg constructor
Field, for which accessor or mutator is generated must be package private or protected
By convention, for classes with names starting with $
sign, Yabk
generates classes with same name by removing $
sign. e.g.
for class abstract class $User
, Yabk
generates public class User
.
If class name is not prepended with $
sign, Yabk
generates classes with same name appended with Yabk
. e.g.
for class abstract class User
, Yabk
generates public class YabkUser
.
If any of the above options do not fill you needs, Yabk
allows defining custom class names in @YabkProcess
annotation. e.g.
for a class annotated with @YabkProcess(className = "CustomUser")
, Yabk
generates a class with name CustomUser
.
Yabk
provides option for generating only accessor or mutator methods. By default it generates both getters and setters. e.g.
For generating only accessors, annotate the class with following annotation
For mutators only, use following annotation
For generating accessor methods which check for null strings and convert them to empty strings, specify nonNullStrings = true
in @YabkProcess
annotation. e.g.
Doesn’t work with generic models
Does not work with POJOs which have wild card types fields
Does not work with fields having nested types
Does not work with bounded type fields
Add following lines to your app level dependency block