<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Atomicity</title>
	<atom:link href="http://atomicityltd.com/feed" rel="self" type="application/rss+xml" />
	<link>http://atomicityltd.com</link>
	<description>Technology, Programming and Learning</description>
	<lastBuildDate>Sun, 08 Jan 2012 04:45:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Custom serialization using Jackson</title>
		<link>http://atomicityltd.com/blog/jackson-custom-serialization</link>
		<comments>http://atomicityltd.com/blog/jackson-custom-serialization#comments</comments>
		<pubDate>Sun, 08 Jan 2012 04:43:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[jackson]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://atomicityltd.com/?p=67</guid>
		<description><![CDATA[Jackson JSON provides many different ways to customize the serialization process of a class, most of these methods utilise annotations on the classes themselves. I recently had the requirement to customize the serialization of a class when I had no access to change the source code of that class. That meant that using annotations wasn't [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://atomicityltd.com/wp-content/uploads/2011/12/unity-codehaus-logo-only.png"><img class="alignright size-full wp-image-68" title="Jackson JSON" src="http://atomicityltd.com/wp-content/uploads/2011/12/unity-codehaus-logo-only.png" alt="" width="82" height="74" /></a>Jackson JSON provides many different ways to customize the serialization process of a class, most of these methods utilise annotations on the classes themselves. I recently had the requirement to customize the serialization of a class when I had no access to change the source code of that class. That meant that using annotations wasn't an option and I had to find another way.</p>
<p>After a fair amount of googling I stumbled across the following page (written by the author of Jackson):</p>
<p><a title="Every day Jackson usage, part 3: Filtering properties" href="http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html" target="_blank">Every day Jackson usage, part 3: Filtering properties</a></p>
<p>There are 7 options detailed in this post, 6 of which use annotations on the class itself. Option 7 is my only option then. Here it is:</p>
<p><span style="color: #0000ff;"><strong>7 . Most extreme way to filter out properties: BeanSerializerModifier</strong></span></p>
<p><span style="color: #0000ff;">And if ability to define custom filters is not enough, the ultimate in configurability is ability to modify configuration and configuration of <strong>BeanSerializer</strong> instances. This makes it possible to do all kinds of modifications (changing order in which properties are serialized; adding, removing or renaming properties; replacing serializer altogether with a custom instance and so on): you can completely re-wire or replace serialization of regular POJO ("bean") types.</span></p>
<p><span style="color: #0000ff;">This is achieved by adding a BeanSerializerModifier: the simplest way to do this is by using<a href="http://wiki.fasterxml.com/JacksonFeatureModules"><span style="color: #0000ff;">Module interface</span></a>. Details of using BeanSerializerModifier are more advanced topic; I hope to cover it separately in future. The basic idea is that BeanSerializerModifier instance defines callbacks that Jackson BeanSerializerFactory calls during construction of a serializer.</span></p>
<p>Right, so now I know what I need to use but there's no details on actually how to use it.</p>
<h2>Classes of interest</h2>
<p>The 3 classes of concern are:</p>
<ul>
<li>org.codehaus.jackson.map.ser.BeanSerializerModifier</li>
<li>org.codehaus.jackson.map.Module</li>
<li>org.codehaus.jackson.map.ObjectMapper</li>
</ul>
<h4>BeanSerializerModifier</h4>
<p>When extended this class provides 4 entry points which can be used to customize the serialization process:</p>
<ol>
<li>changeProperties() - Implementations can add, remove or replace any of passed properties.</li>
<li>orderProperties() - Implementations can change ordering any way they like.</li>
<li>updateBuilder() - Implementations may choose to modify state of builder, or even completely replace it.</li>
<li>modifySerializer() - Implementations can modify or replace given serializer and return serializer to use.</li>
</ol>
<h4>Module</h4>
<p>This is a simple interface used for registering extensions with ObjectMapper. The setupModule() method will be called during initialization and this provides an instance of Module.SetupContext. The method addBeanSerializerModifier() on that context object can then be used to register a custom BeanSerializerModifier.</p>
<h4>ObjectMapper</h4>
<p>This is the main class within Jackson for serializing and deserializing objects, the Module is registered with this object.</p>
<h2>Usage</h2>
<p>Firstly you extend BeanSerializerModifier and override the serialization process in whatever custom way you wish. For example you might wish to reorder the fields and also exclude some. The API for this is well documented, read the <a title="Class BeanSerializerModifier" href="http://jackson.codehaus.org/1.9.0/javadoc/org/codehaus/jackson/map/ser/BeanSerializerModifier.html" target="_blank">javadocs</a>.</p>
<p>Next you need to wire your modifier class into the ObjectMapper and you do this by creating a Module and then registering that with the ObjectMapper using registerModule(). In the setupModule() method in your module you register the new BeanSerilizerModifier.</p>
<h2>Example Code</h2>
<p>To show how this works in practice I've put together a small project that implements a FilteringBeanSerializerModifier, which changes the serialization behaviour of ObjectMapper by filtering out fields on specified classes.</p>
<p>You can find the source code on GitHub here:</p>
<p><a href="https://github.com/ultraflynn/jackson-custom-serialization" target="_blank">https://github.com/ultraflynn/jackson-custom-serialization</a></p>
]]></content:encoded>
			<wfw:commentRss>http://atomicityltd.com/blog/jackson-custom-serialization/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unix disk usage commands</title>
		<link>http://atomicityltd.com/blog/unix-disk-usage-commands</link>
		<comments>http://atomicityltd.com/blog/unix-disk-usage-commands#comments</comments>
		<pubDate>Thu, 17 Nov 2011 18:29:41 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://atomicityltd.com/?p=53</guid>
		<description><![CDATA[When a unix filesystem fills up the first question asked is usually, "Who is using the most disk space?". Naturally there's many ways of finding out but this works for me. du -hc * &#124; sort -n &#124; grep "[0-9]G" This will look for files being measure in Gigabytes and give you a list of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://atomicityltd.com/wp-content/uploads/2011/11/320px-UNIX-Licence-Plate-e1321303734388.jpg"><img class="alignright size-full wp-image-51" title="UNIX Licence Plate" src="http://atomicityltd.com/wp-content/uploads/2011/11/320px-UNIX-Licence-Plate-e1321303734388.jpg" alt="" width="198" height="101" /></a>When a unix filesystem fills up the first question asked is usually, "Who is using the most disk space?". Naturally there's many ways of finding out but this works for me.</p>
<p>du -hc * | sort -n | grep "[0-9]G"</p>
<p>This will look for files being measure in Gigabytes and give you a list of the directories using the most. If your file system has smaller files on them substitute the "G" for "M".</p>
<p>If that produces too many result it can be limited this this.</p>
<p>du -hc --max-depth=1 *snapshots* | sort -n | grep "[0-9]G" | tail</p>
<p>This will only go to one level of depth in the directory structure and will be looking only at directories with the word "snapshots" in them.</p>
<p>This also produces a grand total of files. This will always be displayed last in the output because the sort is numeric and it's the highest number.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomicityltd.com/blog/unix-disk-usage-commands/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ivy and Maven Caching</title>
		<link>http://atomicityltd.com/blog/ivy-and-maven-caching</link>
		<comments>http://atomicityltd.com/blog/ivy-and-maven-caching#comments</comments>
		<pubDate>Sun, 13 Nov 2011 18:02:06 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ivy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[play-framework]]></category>

		<guid isPermaLink="false">http://atomicityltd.com/?p=29</guid>
		<description><![CDATA[The dependency management in Play is a  bit of an afterthought which is being address in V2.0 but for those using V1.X we're stuck with using a Play yaml front-end to Ivy. Most of the time it's absolutely fine but when you are doing local development of non-Play libraries which are stored in a corporate [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://atomicityltd.com/wp-content/uploads/2011/11/ivy-lierre.png"><img class="alignright size-thumbnail wp-image-48" title="ivy-lierre" src="http://atomicityltd.com/wp-content/uploads/2011/11/ivy-lierre-e1321303381485.png" alt="" width="149" height="112" /></a>The dependency management in Play is a  bit of an afterthought which is being address in V2.0 but for those using V1.X we're stuck with using a Play yaml front-end to Ivy. Most of the time it's absolutely fine but when you are doing local development of non-Play libraries which are stored in a corporate Maven repository (such as Nexus) you end up having problems.</p>
<p>The issue stems from the way in which Ivy (and therefore Play) uses those Maven repositories. Maven repositories are configured in the dependencies.yaml file which supports a subset of the behaviour permitted in the .ivy2/ivysettings.xml configuration file. Once Ivy has resolved the dependency it stores a copy in it's local cache to avoid having to load it from the Maven repository again. And this is the problem. What if the artifact changes in the repository? Generally that's not the case, usually you'd expect a new version of an artifact to be deployed to the repository. That is unless it's a SNAPSHOT version, i.e. an ongoing development version, and this is exactly the situation when you are developing a non-Play library and a Play application at the same time.</p>
<p><a href="http://atomicityltd.com/wp-content/uploads/2011/11/Maven_logo-e1321303510856.gif"><img class="alignright size-full wp-image-49" title="Maven" src="http://atomicityltd.com/wp-content/uploads/2011/11/Maven_logo-e1321303510856.gif" alt="" width="150" height="34" /></a>Consider the following situation; you are working on a Play application which uses a library that you are also developing, which is not a Play application. You change that library and you perform a Maven "install" to compile and place the snapshot artifact into you local Maven repository. Then you run your Play application to see whether your Play application works using the new version of the library. This isn't going to work because Ivy has cached the library in it's own local repository. It doesn't look for changed artifacts in the Maven repository, and this makes joint development of Play! applications and non-Play libraries a little tricky.</p>
<p>There is a workaround though, instead of defining the Maven repositories through the dependencies.yaml file you define them as a chained resolver in the .ivy2/ivysettings.xml file and there it's possible to define a "changingPattern" on the resolver which indicates that the resolver should re-check the dependency if it's a SNAPSHOT.</p>
<p>Here's how to do this:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ivysettings&gt;
  &lt;settings defaultResolver="Local Ivy Cache"/&gt;

  &lt;resolvers&gt;
    &lt;ibiblio name="Local Maven Repository" m2compatible="true" usepoms="true"
             root="file:///${user.home}/.m2/repository/"/&gt;

    &lt;ibiblio name="Remote Nexus Repository" m2compatible="true" usepoms="true"
             root="http://nexus.remote.url:8080/nexus/content/groups/code/"/&gt;

    &lt;chain name="Local Ivy Cache" changingPattern=".*-SNAPSHOT"&gt;
      &lt;resolver ref="Local Maven Repository"/&gt;
      &lt;resolver ref="Remote Nexus Repository"/&gt;
    &lt;/chain&gt;
  &lt;/resolvers&gt;
&lt;/ivysettings&gt;</pre>
<pre></pre>
<pre><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">(I'm working on a pure Maven solution for Play so that Ivy isn't involved at all and then this whole problem goes away. It's going to be interesting to see what this process is going to look like when Play v2.X comes along)</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://atomicityltd.com/blog/ivy-and-maven-caching/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unix tail highlighting</title>
		<link>http://atomicityltd.com/blog/unix-tail-highlighting</link>
		<comments>http://atomicityltd.com/blog/unix-tail-highlighting#comments</comments>
		<pubDate>Sun, 13 Nov 2011 09:22:37 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[tail]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://atomicityltd.com/blog/unix-tail-highlighting</guid>
		<description><![CDATA[Often whilst tailing a log file in Unix you want to have the specific thing you are watching for highlighted as it appears. Here are two ways of achieving this. Option 1 - tail/perl t() { tail -f -n5000 $1 &#124; perl -pe "s/$2/\e[1;31;43m$&#38;\e[0m/g" } Option 2 - sed sed filename.txt /string-to-watch-for F]]></description>
			<content:encoded><![CDATA[<p><a href="http://atomicityltd.com/wp-content/uploads/2011/11/320px-UNIX-Licence-Plate-e1321303734388.jpg"><img class="alignright size-full wp-image-51" title="UNIX Licence Plate" src="http://atomicityltd.com/wp-content/uploads/2011/11/320px-UNIX-Licence-Plate-e1321303734388.jpg" alt="" width="198" height="101" /></a>Often whilst tailing a log file in Unix you want to have the specific thing you are watching for highlighted as it appears. Here are two ways of achieving this.</p>
<p><strong>Option 1 - tail/perl</strong></p>
<p>t() {<br />
tail -f -n5000 $1 | perl -pe "s/$2/\e[1;31;43m$&amp;\e[0m/g"<br />
}</p>
<p><strong>Option 2 - sed</strong></p>
<p>sed filename.txt<br />
/string-to-watch-for<br />
F</p>
]]></content:encoded>
			<wfw:commentRss>http://atomicityltd.com/blog/unix-tail-highlighting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

