<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mirko</title>
    <description>The latest articles on DEV Community by mirko (@mirkoperillo).</description>
    <link>https://dev.to/mirkoperillo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F227636%2Fe118a678-4e18-4e01-bae7-d8076842b0d4.png</url>
      <title>DEV Community: mirko</title>
      <link>https://dev.to/mirkoperillo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mirkoperillo"/>
    <language>en</language>
    <item>
      <title>Serializing an enum in a Spring Boot web application</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Wed, 08 Jan 2025 20:46:07 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/serializing-an-enum-in-a-spring-boot-web-application-58d9</link>
      <guid>https://dev.to/mirkoperillo/serializing-an-enum-in-a-spring-boot-web-application-58d9</guid>
      <description>&lt;p&gt;Enum is a good structure to define a set of limited and well defined values inside the domain of our application. They could help to prevent impossible states in our codebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  The scenario
&lt;/h2&gt;

&lt;p&gt;Let's use a note taking web application as an example to show the possible ways to serialize and deserialize an eum value.&lt;/p&gt;

&lt;p&gt;We are going to implement it using Spring Boot 3.3.x and MongoDB.&lt;/p&gt;

&lt;p&gt;We define a &lt;code&gt;Type&lt;/code&gt; enum class to represent the permitted types of todos inside the application: events and activities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;EVENT&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"event"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="no"&gt;ACTIVITY&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"activity"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our &lt;code&gt;Todo&lt;/code&gt; class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Todo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are going to analyze enum serialization in these scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enum as query param.&lt;/li&gt;
&lt;li&gt;Enum as part of a JSON body request.&lt;/li&gt;
&lt;li&gt;Enum as a field of a MongoDB document.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Enum as query param
&lt;/h3&gt;

&lt;p&gt;In this scenario we need only a deserialize method because we are interested in transforming from a string value to the enum.&lt;/p&gt;

&lt;p&gt;Below a snippet of code representing the Controller method to read all todos by types, the type is passed as a query parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Collection&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Todo&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestParam&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;required&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
     &lt;span class="o"&gt;...&lt;/span&gt;
     &lt;span class="o"&gt;...&lt;/span&gt;
 &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The query parameter is a string so we have to define an appropriate &lt;code&gt;Converter&lt;/code&gt; to transform it.&lt;br&gt;
Inside the &lt;code&gt;convert&lt;/code&gt; method we call &lt;code&gt;Type.fromString&lt;/code&gt;, a static method created in the enum class, that will be used in other scenarios too. The code of &lt;code&gt;fromString&lt;/code&gt; method is presented in the next scenario.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StringToType&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Converter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fromString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The converter must be registered in the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Configuration&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Config&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;WebMvcConfigurer&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;addFormatters&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;FormatterRegistry&lt;/span&gt; &lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addConverter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringToType&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="nc"&gt;WebMvcConfigurer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addFormatters&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when we will use &lt;code&gt;Type&lt;/code&gt; as a &lt;code&gt;RequestParam&lt;/code&gt; the &lt;code&gt;StringToType&lt;/code&gt; converter will be used to try converting string values in our enum.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enum as part of JSON body request
&lt;/h3&gt;

&lt;p&gt;To manage correctly the enum as a field of the JSON body content we should add some code to the enum &lt;code&gt;Type&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;We need to use the annotation &lt;code&gt;@JsonValue&lt;/code&gt; to mark the field as the value to use for serializing the enum.&lt;br&gt;
Then we should add a static map inside the enum to map the Type with the related string representation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;EVENT&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"event"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="no"&gt;ACTIVITY&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"activity"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="nd"&gt;@JsonValue&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;enumMap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;enumMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toMap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="nf"&gt;fromString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;enumMap&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Enum as a field of a MongoDB document.
&lt;/h3&gt;

&lt;p&gt;To manage the serialization/deserialization of a enum in a MongoDB document we have to use the &lt;code&gt;@ValueConverter&lt;/code&gt; annotation that binds a field of the document with a specific &lt;code&gt;PropertyValueConverter&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;In the example the field &lt;code&gt;Type type&lt;/code&gt; is bound with the &lt;code&gt;MongoEnumConverter&lt;/code&gt; that provide &lt;code&gt;read&lt;/code&gt; and &lt;code&gt;write&lt;/code&gt; methods to manage the conversion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Document&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"todo"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nd"&gt;@TypeAlias&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"todo"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Todo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Id&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@ValueConverter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MongoEnumConverter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setId&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;isCompleted&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setCompleted&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="nf"&gt;getType&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setType&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In detail in the &lt;code&gt;read&lt;/code&gt; method we call &lt;code&gt;Type.fromString&lt;/code&gt; from the enum class to try to convert the string in a valid Type instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MongoEnumConverter&lt;/span&gt;
        &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;PropertyValueConverter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueConversionContext&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueConversionContext&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fromString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueConversionContext&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;In this article I presented some ways to manage the serialization/deserializion of a enum class in a typical Web scenario. Spring and the Jackson library provide some facilities to simplify this work.&lt;/p&gt;

&lt;p&gt;The code is publically available in this &lt;a href="https://gitlab.com/mirkoperillo/spring-enum-serialization" rel="noopener noreferrer"&gt;Gitlab repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The code presented in this article are under CC0 license.&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
    </item>
    <item>
      <title>Elm, an alternative to Javascript</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Sat, 05 Nov 2022 10:41:54 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/elm-an-alternative-to-javascript-1cmo</link>
      <guid>https://dev.to/mirkoperillo/elm-an-alternative-to-javascript-1cmo</guid>
      <description>&lt;h2&gt;
  
  
  What is Elm ?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://elm-lang.org/"&gt;Elm&lt;/a&gt; is a pure functional programming language with a strong type system. It is Open Source (released under BSD-3-Clause license) and this year is 10 years old.&lt;/p&gt;

&lt;p&gt;The current version is &lt;code&gt;0.19.1&lt;/code&gt; and it is surrounded by an active community.&lt;/p&gt;

&lt;p&gt;Elm is "domain-specific", its goal is to help you building front-end web applications.&lt;br&gt;
The compiler produces optimized Javascript code to run into the browser. It supports developer with a detailed and more clear as possible output to help resolve errors. &lt;/p&gt;

&lt;p&gt;An example of compiler output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;naming&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;
&lt;span class="kt"&gt;Line&lt;/span&gt; &lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Column&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;
&lt;span class="kt"&gt;I&lt;/span&gt; &lt;span class="n"&gt;cannot&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="kt"&gt;Timestamp&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;       &lt;span class="n"&gt;ts&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Timestamp&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
               &lt;span class="o"&gt;^^^^^^^^^&lt;/span&gt;
&lt;span class="kt"&gt;These&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="n"&gt;seem&lt;/span&gt; &lt;span class="n"&gt;close&lt;/span&gt; &lt;span class="n"&gt;though&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="kt"&gt;Timstamp&lt;/span&gt;
    &lt;span class="kt"&gt;Time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Zone&lt;/span&gt;
    &lt;span class="kt"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Task&lt;/span&gt;
    &lt;span class="kt"&gt;Time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Month&lt;/span&gt;

&lt;span class="kt"&gt;Hint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Read&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;elm&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;0.19&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;imports&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;see&lt;/span&gt; &lt;span class="n"&gt;how&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt;
&lt;span class="n"&gt;declarations&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="kt"&gt;Elm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is an online editor, named &lt;a href="https://ellie-app.com"&gt;Ellie&lt;/a&gt;, to play with the language without the need to install anything on your machine.&lt;br&gt;
Ellie permits to install dependencies for your code, so you can prototype an entire project with it.&lt;/p&gt;

&lt;p&gt;Applications in Elm follow the TEA (The Elm Architecture), an architectural pattern based on the following concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model: the state of the application.&lt;/li&gt;
&lt;li&gt;View: transforms model into HTML code.&lt;/li&gt;
&lt;li&gt;Update: updates the model intercepting messages which came from the user interaction with the view.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Elm ?
&lt;/h2&gt;

&lt;p&gt;I started using Elm because I wanted to experience with the functional paradigm. &lt;br&gt;
I tried it using Javascript, but its multi-paradigm nature didn't help me in having a focused functional experience, so I decided to try with an only-functional language and I discovered Elm, described as a good first step into the functional world.&lt;/p&gt;

&lt;p&gt;To take practice with Elm I implemented a tiny project &lt;a href="https://github.com/mirkoperillo/ts-converter"&gt;ts-converter&lt;/a&gt;: a browser extension to translate timestamps into human readable dates.&lt;br&gt;
Ts-converter is released as a libre software under GPLv3 license.&lt;/p&gt;

</description>
      <category>elm</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My first experience with Vala</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Wed, 19 Oct 2022 07:11:17 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/my-first-experience-with-vala-4dfi</link>
      <guid>https://dev.to/mirkoperillo/my-first-experience-with-vala-4dfi</guid>
      <description>&lt;p&gt;This article is a short resume of my first experience with &lt;a href="https://vala.dev/"&gt;Vala&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Vala
&lt;/h2&gt;

&lt;p&gt;Vala is an object-oriented programming language with a syntax very similar to C#.&lt;br&gt;
The compiler could produce a native binary or generate C code.&lt;/p&gt;

&lt;p&gt;The current version is 0.56, meanwhile I used the 0.54.1.&lt;/p&gt;

&lt;p&gt;The language was born in 2006 and although it hasn't reach the version 1.0 it's used in a lot of GNOME applications and it's the main choice for implementing application in Elementary OS. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Vala
&lt;/h2&gt;

&lt;p&gt;I'm interested in the creation of GTK applications for Linux.&lt;br&gt;
The possibilities I found to reach this goal are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use C, but I used it only for an exam in my first university years. I was afraid to not reach a concrete result in a short time.&lt;/li&gt;
&lt;li&gt;Use Python, probably the simple solution, but I was interested in creating a native application.&lt;/li&gt;
&lt;li&gt;Use Go, but my perception was that the GTK libraries for Go were immature and incomplete.&lt;/li&gt;
&lt;li&gt;Use Rust, but I was intimidated by the steep learning curve.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I decided to explore Vala because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it's a language created by the GNOME Foundation with the scope to permit the implementation of native GNOME (so GTK) application at a high level.&lt;/li&gt;
&lt;li&gt;it's well integrated with GTK libraries so it permits to be immediately operative.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  First impressions
&lt;/h2&gt;

&lt;p&gt;Some considerations after this short experience.&lt;/p&gt;

&lt;p&gt;I have to admit that it has been not so easy to reach my goal. I think that a lot of problems and slowness has been caused by my inexperience in developing desktop applications in general.&lt;/p&gt;

&lt;p&gt;The official Vala documentation is &lt;a href="https://valadoc.org"&gt;valadoc.org&lt;/a&gt;.&lt;br&gt;
I found the ecosystem of libraries around the language still immature: it's not easy to found information or examples (and often when you find something it's pretty old). There isn't a standardization of the documentation of the libraries. This fact doesn't help a newbie.&lt;/p&gt;

&lt;p&gt;Looking some examples implemented in Python, it helped me a lot to understand how to use notifications and how to implement an indicator (the main part of my little experiment).&lt;/p&gt;

&lt;p&gt;In the next future I'm going to try again to implement other simple applications using Vala.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pommy
&lt;/h2&gt;

&lt;p&gt;Pommy is a simple timer to measure an activity duration. It's an indicator staying in the notification bar and it notifies you the end of the activity session.&lt;/p&gt;

&lt;p&gt;It takes inspirations from &lt;a href="https://github.com/abo-abo/gtk-pomodoro-indicator"&gt;gtk-pomo-indicator&lt;/a&gt;, a Python application I used for years to break my daily routine into work sessions, following some concepts from the pomodoro tecnique.&lt;/p&gt;

&lt;p&gt;Pommy is released under GPLv3 and it is available &lt;a href="https://github.com/mirkoperillo/pommy"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>vala</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Four rules to maintain the motivation high working to your projects</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Sat, 20 Nov 2021 16:17:13 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/four-rules-to-maintain-the-motivation-high-working-to-your-projects-md9</link>
      <guid>https://dev.to/mirkoperillo/four-rules-to-maintain-the-motivation-high-working-to-your-projects-md9</guid>
      <description>&lt;p&gt;&lt;a href="http://resting.owlcode.eu/"&gt;Resting&lt;/a&gt; is the most long-lived side-project of mine.&lt;br&gt;
I have been working on it since December 2017.&lt;/p&gt;

&lt;p&gt;It's not easy to maintain the focus on the same project for such a long time: so many mermaids try to attract your attention in new wonderful projects 🧜‍♀️🧜‍♀️🧜‍♀️🧜‍♀️🧜‍♀️🧜‍♀️.&lt;/p&gt;

&lt;p&gt;I think the main obstacle is to keep the motivation on the project.&lt;/p&gt;

&lt;p&gt;These are four advises to maintain the motivation high.&lt;/p&gt;

&lt;h2&gt;
  
  
  Schedule a daily window
&lt;/h2&gt;

&lt;p&gt;Schedule a moment to work to your project every day. I don't think it's important to invest a big amount of time, but to preserve this moment ongoing.&lt;/p&gt;

&lt;p&gt;I believe that even 15/30 minutes per day are enough and the results will be visible after some time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discuss with a friend
&lt;/h2&gt;

&lt;p&gt;It's important to have someone to speak with. It helps you to understand the evolution of the project.&lt;/p&gt;

&lt;p&gt;If you haven't the lucky to speak to someone, think about enter in a focused online community like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.indiehackers.com/"&gt;Indie Hackers&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;LinkedIn &lt;a href="https://www.linkedin.com/groups/13568032/"&gt;Side-projects&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;subreddit &lt;a href="https://www.reddit.com/r/SideProject/"&gt;SideProject&lt;/a&gt;,&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Spread your project
&lt;/h2&gt;

&lt;p&gt;Take the courage of speaking publicly about your project. You have to move the project from your head to the real world.&lt;/p&gt;

&lt;p&gt;Public speaking about it makes your project real and creates good expectations about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Take a short development iteration
&lt;/h2&gt;

&lt;p&gt;Take a short development cycle of your project. This permits you to perceive the real progress of your project and to be more flexible about the future.&lt;br&gt;
Your enthusiasm increases perceiving the effective progress of your project.&lt;/p&gt;

&lt;p&gt;Don't be a perfectionist: it's better to release an idea of the feature and improve it in the next iterations.&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Retrospective of an hackathon</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Tue, 31 Aug 2021 12:18:07 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/retrospective-of-an-hackathon-5a7o</link>
      <guid>https://dev.to/mirkoperillo/retrospective-of-an-hackathon-5a7o</guid>
      <description>&lt;p&gt;Yesterday I found some notes written the past year about a personal retrospective after the participation to my first remote hackathon.&lt;/p&gt;

&lt;p&gt;I want to share with you some hints I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There are a lot of tools to organize and manage the work of a remote team without too much pains.&lt;br&gt;
Well, but I think everybody learned it in these strange time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use every library, framework or everything else you know to prototype the result in a quick way. In this context: "the idea is better than the solidity of the solution".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Invest some time implementing a base build and deploy workflow will have great ROI in the last part of event.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Invest more time into the initial brainstorming and then plan some global checkpoints to fix the idea.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do few quick video chat and maintain an active textual chat to align in real time the team about the progress of single tasks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simplify, simplify and simplify.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Be available and pro-active.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Work to unblock the work of other members of the team.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Italian 🇮🇹 speakers can found the article &lt;a href="https://www.owlcode.eu/blog/cosa-resta-di-un-hackathon/"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Port react tutorial in vuejs</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Wed, 07 Jul 2021 09:38:07 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/port-react-tutorial-in-vuejs-1c5</link>
      <guid>https://dev.to/mirkoperillo/port-react-tutorial-in-vuejs-1c5</guid>
      <description>&lt;p&gt;To improve my vuejs skill I decided to take the tic-tac-toe game from the reactjs tutorial and re-implement it in vue 2.x + vuex&lt;/p&gt;

&lt;p&gt;The result is available on Github under CC0 license, &lt;a href="https://github.com/mirkoperillo/vue-tic-tac-toe"&gt;here&lt;/a&gt;&lt;br&gt;
Every comment or suggestion to improve the code is welcome 🙏&lt;/p&gt;

</description>
      <category>vue</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>An emulator of enigma machine</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Sun, 18 Apr 2021 18:39:26 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/an-emulator-of-enigma-machine-4343</link>
      <guid>https://dev.to/mirkoperillo/an-emulator-of-enigma-machine-4343</guid>
      <description>&lt;p&gt;Hi, it's Mirko here.&lt;/p&gt;

&lt;p&gt;During the last weeks I've worked on another funny project to improve my go knowledge.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is it ?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/mirkoperillo/enigma"&gt;Enigma&lt;/a&gt; is a emulator of the &lt;a href="https://en.wikipedia.org/wiki/Enigma_machine"&gt;enigma&lt;/a&gt; M3 machine, become famous during the II world war and used by nazist army to crypt&lt;br&gt;
their communications.&lt;/p&gt;

&lt;p&gt;The project is published on Github and it is released under the Creative Commons Zero license.&lt;/p&gt;

&lt;p&gt;Every feedback about the code or project features is very welcome 🙏🏻&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>go</category>
    </item>
    <item>
      <title>A toy shell to play with go</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Tue, 13 Apr 2021 13:33:17 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/a-toy-shell-to-play-with-go-1jd8</link>
      <guid>https://dev.to/mirkoperillo/a-toy-shell-to-play-with-go-1jd8</guid>
      <description>&lt;p&gt;Hi it's Mirko here.&lt;/p&gt;

&lt;p&gt;My learning about go continues.&lt;/p&gt;

&lt;p&gt;I have created another learning project to play with the language syntax.&lt;br&gt;
&lt;a href="https://github.com/mirkoperillo/gosh"&gt;Gosh&lt;/a&gt; is a simple toy shell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Builtin functions: ciao, bye&lt;/li&gt;
&lt;li&gt;Suggestion of command options&lt;/li&gt;
&lt;li&gt;Possibility to extend suggestions to other commands&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The project is available on Github and it is released under Common Creative Zero lincense&lt;/p&gt;

&lt;p&gt;Any feedback about the code or the features is welcome!! 🙏🏻&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>go</category>
    </item>
    <item>
      <title>A tool to download attachments from Gmail</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Fri, 09 Apr 2021 10:03:16 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/a-tool-to-download-attachments-from-gmail-373o</link>
      <guid>https://dev.to/mirkoperillo/a-tool-to-download-attachments-from-gmail-373o</guid>
      <description>&lt;p&gt;Hi I'm Mirko.&lt;br&gt;
Some months ago I have started learning Go in my free time, because I'm very interesting about it.&lt;/p&gt;

&lt;p&gt;The best way I know to learn a new programming language is to use it into a tiny but real and useful (at least for me) project.&lt;/p&gt;

&lt;p&gt;This is the story behind &lt;a href="https://github.com/mirkoperillo/gmail-downloader"&gt;gmail-downloader&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is it ?
&lt;/h2&gt;

&lt;p&gt;It's a cli tool that permits to download all email attachments selecting a particular label from Gmail.&lt;br&gt;
It uses the official google go sdk for gmail.&lt;/p&gt;

&lt;p&gt;It's my first experiment using Go and it is released on Github with GPLv3 license.&lt;br&gt;
Every feedback about the code or the features is very welcome 🙏🏻&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>go</category>
    </item>
    <item>
      <title>Event listeners in Elm</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Thu, 28 May 2020 20:15:57 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/event-listeners-in-elm-6m3</link>
      <guid>https://dev.to/mirkoperillo/event-listeners-in-elm-6m3</guid>
      <description>&lt;p&gt;I am a beginner in Elm and to learn it I have started &lt;a href="https://github.com/mirkoperillo/ts-converter?src=external-dev"&gt;ts-converter&lt;/a&gt;, a tiny browser extension to convert timestamps in a readable format. This is one of my daily needs.&lt;br&gt;
I want to use what I have learnt from it, sharing some notes on how to manage event listeners in a Elm application.&lt;br&gt;
I'll use &lt;code&gt;onEnter&lt;/code&gt; event in the examples.&lt;/p&gt;
&lt;h2&gt;
  
  
  Scenario 1: Listen for all application events
&lt;/h2&gt;

&lt;p&gt;To capture a key pressed in the whole application we need to introduce a &lt;code&gt;subscription&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  What's a subscription ?
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;subscription&lt;/code&gt; is an operation allowing us to register to an external event.&lt;br&gt;
Creating a subscription we say to Elm runtime that we want to do an action when a particular event is spawned. When the runtime captures an event, produces an update message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;subscriptions _ =
  onKeyPress keyDecoder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A subscription is created on event &lt;code&gt;onKeyPress&lt;/code&gt; and when this event will be intercepted by the Elm runtime the function &lt;code&gt;keyCoder&lt;/code&gt; will be invoked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;keyDecoder : Decode.Decoder Msg
keyDecoder =
    Decode.map toKey (Decode.field "key" Decode.string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The event object is serialized as a JSON object and its field &lt;code&gt;key&lt;/code&gt; contains the key pressed value, &lt;code&gt;Decode.field "key" Decode.string&lt;/code&gt; extracts this number and puts it into a valid Elm value. &lt;br&gt;
The extracted value is then passed to &lt;code&gt;toKey&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;toKey : String -&amp;gt; Msg
toKey keyValue =
    case String.uncons keyValue of
        Just ( char, "" ) -&amp;gt;
            CharacterKey char
        _ -&amp;gt;
            ControlKey keyValue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;String.uncons&lt;/code&gt; takes a string as a characters array and splits it into its head and tail.&lt;br&gt;
Depending on whether the leading character is an alphanumeric value&lt;br&gt;
or not, produces the related &lt;code&gt;update&lt;/code&gt; message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CharacterKey k -&amp;gt;
     YOUR CODE
ControlKey k -&amp;gt;
     YOUR CODE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two messages will be managed into the &lt;code&gt;update&lt;/code&gt; function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenario 2: Listen for a event bound to a input field
&lt;/h2&gt;

&lt;p&gt;At the moment (v0.19) Elm doesn't support natively &lt;code&gt;onEnter&lt;/code&gt; event, but it offers a function &lt;code&gt;on&lt;/code&gt; that permits to create a custom event listener.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onEnter: Msg -&amp;gt; Attribute Msg
onEnter msg =
  let 
    isEnter code = 
      if code == 13 then
        Decode.succeed msg
      else
        Decode.fail "not ENTER"
  in
on "keydown" (Decode.andThen isEnter keyCode)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;on "keydown" (Decode.andThen isEnter keyCode)&lt;/code&gt; we'll create a listener on &lt;code&gt;keydown&lt;/code&gt; event and the Elm runtime will execute &lt;code&gt;(Decode.andThen isEnter keyCode)&lt;/code&gt; on its capture.&lt;br&gt;
&lt;code&gt;keyCode&lt;/code&gt; is a bultin function of &lt;code&gt;Html.Events&lt;/code&gt; module and it returns the value of pressed key as an integer.&lt;br&gt;
&lt;code&gt;isEnter&lt;/code&gt; checks if key &lt;code&gt;enter&lt;/code&gt; has been pressed (enter value is 13) producing respectively a message for the &lt;code&gt;update&lt;/code&gt; function or a failure.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onEnter&lt;/code&gt; is used into the input field we will listen for events.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;input [ size 20, value (tsToString model.ts), onInput SetTs, onEnter Convert, autofocus True] []&lt;/code&gt;&lt;/p&gt;

</description>
      <category>elm</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My side project Resting</title>
      <dc:creator>mirko</dc:creator>
      <pubDate>Wed, 13 Nov 2019 15:56:26 +0000</pubDate>
      <link>https://dev.to/mirkoperillo/my-side-project-resting-405h</link>
      <guid>https://dev.to/mirkoperillo/my-side-project-resting-405h</guid>
      <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;in the last two years I have dedicated some my spare time to a side project called Resting.&lt;br&gt;
Resting is a browser extension that permits to analyze and test HTTP and REST APIs.&lt;br&gt;
The mission of Resting is to simplify daily work of developer in testing and analyzing HTTP/REST requests.&lt;/p&gt;

&lt;p&gt;Resting takes inspiration from Postman with the goal to be light and focused on the management of saved requests.&lt;/p&gt;

&lt;p&gt;It is a Open Source project hosted by Github and it is a community friendly project.&lt;br&gt;
Here is the &lt;a href="https://github.com/mirkoperillo/resting"&gt;Github repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm very interested in some feedback about the tool&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
