A Handler is an implementation of the PibifyGenerated<T>
abstract class. It primarily has 2 methods
public abstract T deserialize(IDeserializer deserializer, Class<T> type, SerializationContext context)
throws PibifyCodeExecException;
public abstract void serialize(T object, ISerializer serializer, SerializationContext context)
throws PibifyCodeExecException;
The Pibify Maven plugin generates a concrete implementation of this abstract class.
For every class in the maven module annotated with @Pibify
, a handler is generated. The handler is named as
<ClassName>Handler
.
Few handlers are provided out of the box. They are:
- PibifyObjectHandler - for cases where the reference type is
java.lang.Object
- PibifyMapHandler - for cases where the reference type is
java.util.Map
with missing type parameters - PibifyCollectionHandler - for cases where the reference type is
java.util.Collection
with missing type parameters - BigDecimalHandler - for cases where the reference type is
java.math.BigDecimal
- DateHandler - for cases where the reference type is
java.util.Date
This well-known handlers are registered in AbstractPibifyHandlerCache
's protected constructor.
If you want to add custom handlers, you can do so by extending the AbstractPibifyHandlerCache
class and registering
your custom handlers in the constructor.
public class CustomHandlerCache extends AbstractPibifyHandlerCache {
public CustomHandlerCache() {
super();
// Type is the class type of the object
super.mapBuilder.put(type, new CustomHandler());
}
}
Then merge CustomHandlerCache
with the generated PibifyHandlerCache
using MultiModuleHandlerCache
:
new MultiModulePibifyHandlerCache(new CustomHandlerCache(), new PibifyHandlerCache());