Marshallers

Db4o marshaller implementation uses reflection to detect class fields.  This approach is universal, but reflection usage imposes a certain performance penalty. In some cases you may want to improve the performance using custom marshallers through a plug-in interface:

Java: 

Db4o.configure().objectClass(YourClass.class).marshallWith(yourMarshaller);

Custom marshaller provides a functionality to convert object fields to a byte array and back. This approach allows to achieve a better performance due to the following:

  • reflection is not used to detect object fields;
  • only the required fields need to be marshalled.

However there are certain limitations:

  • custom marshaller is not compatible with the use of a translator;
  • quering for fields is not possible when a custom marshaller is used. 

Custom marshallers should implement an ObjectMarshaller interface:

Java: 

public class CustomMarshaller implements ObjectMarshaller

To simplify the task of creating custom marshallers db4o provides a PrimitiveCodec class, which implements write and read functions for int and long values.