title: Handling UUID in Avro java
body: <p>I want to store a uuid using avro.
  below is the schema i am using</p>
  <pre><code>
    {
      &quot;namespace&quot;: &quot;somethingImportant&quot;,
      &quot;type&quot;: &quot;record&quot;,
      &quot;name&quot;: &quot;GoodObject&quot;,
      &quot;fields&quot;: [
        {
          &quot;name&quot;: &quot;pk&quot;,
          &quot;type&quot;: {&quot;type&quot;: &quot;string&quot;, &quot;logicalType&quot;: &quot;uuid&quot;}
        }
      ]
    }
  </code></pre>
  <p>i am using maven plugin 1.10.2 plugin with the below config</p>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.avro&lt;/groupId&gt;
      &lt;artifactId&gt;avro-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.10.2&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;schemas&lt;/id&gt;
              &lt;phase&gt;generate-sources&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;schema&lt;/goal&gt;
                  &lt;goal&gt;protocol&lt;/goal&gt;
                  &lt;goal&gt;idl-protocol&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                  &lt;stringType&gt;String&lt;/stringType&gt;
                  &lt;customConversions&gt;org.apache.avro.Conversions$UUIDConversion&lt;/customConversions&gt;
                  &lt;enableDecimalLogicalType&gt;true&lt;/enableDecimalLogicalType&gt;
                  &lt;sourceDirectory&gt;${project.basedir}/src/main/resources/&lt;/sourceDirectory&gt;
                  &lt;outputDirectory&gt;${project.basedir}/src/main/java/&lt;/outputDirectory&gt;
              &lt;/configuration&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  <p>the generated class the id field is generated as UUID, and i can do a get and set of uuid.</p>
  <p>But uuid is stored as a string(36 bytes) which defeats the purpose. I came across another solution to define seomthing like</p>
  <pre><code>
  {
    &quot;namespace&quot;: &quot;somethingImportant&quot;,
    &quot;type&quot;: &quot;record&quot;,
    &quot;name&quot;: &quot;GoodObject&quot;,
    &quot;fields&quot;: [
      {
        &quot;name&quot;: &quot;pk&quot;,
        &quot;type&quot;: {&quot;type&quot;: &quot;string&quot;, &quot;logicalType&quot;: &quot;uuid&quot;, &quot;CustomEncoding&quot;:&quot;UUIDAsBytesEncoding&quot;}
      }
    ]
  }
  </code></pre>
  <p>but this does not do anything on its own. <a href="https://stackoverflow.com/a/31955223">This</a> stackoverflow answer talks about implementation, but i am not sure how we can make it work with maven plugin. <a href="https://liyanxu.blog/category/computer-science/java/page/4/" rel="nofollow noreferrer">This</a> blog also talks about similar thing but i could not generate @AvroEncode(using = InstantAsStringAvroEncoding.class).</p>
  <p>Has someone used uuid with avro so that</p>
  <ol>
  <li>we can set a uuid</li>
  <li>it gets stored as byte array</li>
  <li>The Get method returns a uuid</li>
  </ol>
  <p>I don't want to do the marshelling and unmarshelling by myself obviously because that is a custom code to maintain</p>