Skip to content


Codec decorators in Preon: The right way

Here's the wrong way to use decorators in Preon. They'll only work on the first level, and won't apply to nested Preon objects.

final DefaultCodecFactory fact = new DefaultCodecFactory();
Codec<MyFileType> codec = fact.create(MyFileType.class);
final LoggingDecorator ld = new LoggingDecorator(new CustomLogger());
codec = ld.decorate(codec,null,MyFileType.class,null);
// Resulting codec only does outermost-level logging.

The right way appears to be:

final DefaultCodecFactory fact = new DefaultCodecFactory();
final CodecDecorator[] decorators = new CodecDecorator[]{
    new LoggingDecorator(new CustomLogger())
};
final Codec<MyFileType> codec = fact.create(null, MyFileType.class, new CodecFactory[]{},decorators);
I haven't found any other way to alter the decorator-chain yet.

Posted in Uncategorized.

Tagged with .