{"id":850,"date":"2010-12-09T02:06:23","date_gmt":"2010-12-09T10:06:23","guid":{"rendered":"http:\/\/technofovea.com\/blog\/?p=850"},"modified":"2010-12-09T02:08:19","modified_gmt":"2010-12-09T10:08:19","slug":"codec-decorators-in-preon-the-right-way","status":"publish","type":"post","link":"http:\/\/technofovea.com\/blog\/archives\/850","title":{"rendered":"Codec decorators in Preon: The right way"},"content":{"rendered":"<p>Here&#8217;s the <strong>wrong<\/strong> way to use decorators in Preon. They&#8217;ll only work on the first level, and won&#8217;t apply to nested Preon objects.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nfinal DefaultCodecFactory fact = new DefaultCodecFactory();\r\nCodec&lt;MyFileType&gt; codec = fact.create(MyFileType.class);\r\nfinal LoggingDecorator ld = new LoggingDecorator(new CustomLogger());\r\ncodec = ld.decorate(codec,null,MyFileType.class,null);\r\n\/\/ Resulting codec only does outermost-level logging.\r\n<\/pre>\n<p>The right way appears to be:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfinal DefaultCodecFactory fact = new DefaultCodecFactory();\r\nfinal CodecDecorator[] decorators = new CodecDecorator[]{\r\n    new LoggingDecorator(new CustomLogger())\r\n};\r\nfinal Codec&lt;MyFileType&gt; codec = fact.create(null, MyFileType.class, new CodecFactory[]{},decorators);\r\n<\/pre>\n<p>I haven&#8217;t found any other way to alter the decorator-chain yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s the wrong way to use decorators in Preon. They&#8217;ll only work on the first level, and won&#8217;t apply to nested Preon objects. The right way appears to be: I haven&#8217;t found any other way to alter the decorator-chain yet.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[20],"_links":{"self":[{"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/posts\/850"}],"collection":[{"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/comments?post=850"}],"version-history":[{"count":4,"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/posts\/850\/revisions"}],"predecessor-version":[{"id":853,"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/posts\/850\/revisions\/853"}],"wp:attachment":[{"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/media?parent=850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/categories?post=850"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/technofovea.com\/blog\/wp-json\/wp\/v2\/tags?post=850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}