<?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: Mihai A.</title>
    <description>The latest articles on DEV Community by Mihai A. (@amihaiemil).</description>
    <link>https://dev.to/amihaiemil</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%2F79283%2F00f44d9d-4ce8-4a2e-af47-c8adefb82bfb.png</url>
      <title>DEV Community: Mihai A.</title>
      <link>https://dev.to/amihaiemil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amihaiemil"/>
    <language>en</language>
    <item>
      <title>Modern YAML For Modern Java</title>
      <dc:creator>Mihai A.</dc:creator>
      <pubDate>Tue, 14 Apr 2020 16:57:52 +0000</pubDate>
      <link>https://dev.to/amihaiemil/modern-yaml-for-modern-java-1f9g</link>
      <guid>https://dev.to/amihaiemil/modern-yaml-for-modern-java-1f9g</guid>
      <description>&lt;p&gt;Since Java does not have a standard API for YAML and since, starting YAML 1.2, the format is supposed to be a superset of JSON, we decided to create a parser which closely follows the API and encapsulation of &lt;a href="https://javaee.github.io/jsonp/"&gt;JSON-P (JSR 374)&lt;/a&gt;. With this idea in mind, &lt;a href="https://github.com/decorators-squad/eo-yaml"&gt;eo-yaml&lt;/a&gt; took shape.&lt;/p&gt;

&lt;p&gt;Unlike other YAML libraries on the market, eo-yaml is fully encapsulated and has an API-first design -- the user works with only a few intuitive Java Interfaces, all the implementations being hidden. This also opens the door for different providers: you don't like the reference implementation? Cool, implement those interfaces yourself and keep using the same API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;The entry point for building, reading, dumping or loading YAML is class &lt;code&gt;com.amihaiemil.eoyaml.Yaml&lt;/code&gt;. Here's a short overview:&lt;/p&gt;

&lt;h4&gt;
  
  
  Building YAML
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;YamlMapping&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Yaml&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createYamlMappingBuilder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"architect"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"amihaiemil"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"devops"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Yaml&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createYamlSequenceBuilder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"rultor"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"0pdd"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DevOps Tools"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"developers"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Yaml&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createYamlSequenceBuilder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"amihaiemil"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"salikjan"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SherifWally"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Project Team"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//toString() methods overriden to pretty-print the YAML&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The printed YAML will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Project Team&lt;/span&gt;
&lt;span class="na"&gt;architect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;amihaiemil&lt;/span&gt;
&lt;span class="c1"&gt;# DevOps Tools&lt;/span&gt;
&lt;span class="na"&gt;devops&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;rultor&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;0pdd&lt;/span&gt;
&lt;span class="na"&gt;developers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;amihaiemil&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;salikjan&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;SherifWally&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Reading YAML
&lt;/h4&gt;

&lt;p&gt;Reading YAML is as simple as (you can read from a &lt;code&gt;File&lt;/code&gt;, from an &lt;code&gt;InputStream&lt;/code&gt; or from a &lt;code&gt;String&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;YamlMapping&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Yaml&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createYamlInput&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;File&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"team.yml"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;readYamlMapping&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Dumping YAML (Bean-to-Yaml)
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;YamlMapping&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Yaml&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createYamlDump&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;(...)&lt;/span&gt;&lt;span class="c1"&gt;//bean with getters and setters&lt;/span&gt;
&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;dump&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  JDK Integration
&lt;/h1&gt;

&lt;p&gt;The API is integrated with the JDK where possible: for instance, a &lt;code&gt;YamlSequence&lt;/code&gt; implements &lt;code&gt;Iterable&amp;lt;YamlNode&amp;gt;&lt;/code&gt; and a &lt;code&gt;YamlStream&lt;/code&gt; (a collection of more YAML documents) implements Java 8's Stream API.&lt;/p&gt;

&lt;h1&gt;
  
  
  Java Module
&lt;/h1&gt;

&lt;p&gt;The library is and will be primarily Java 8 compatible. However, it is packaged as a Module, so it can be used as such if you are on Java 9 or higher.&lt;/p&gt;

&lt;h1&gt;
  
  
  Easy Extension
&lt;/h1&gt;

&lt;p&gt;Since it is based on interfaces, you can easily create your own decorators or implementations on top of the existing ones to enhance or create new functionality. More in the &lt;a href="https://github.com/decorators-squad/eo-yaml/wiki/Easy-Extension-Via-Interfaces"&gt;Wiki&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Often and Fast Releases
&lt;/h1&gt;

&lt;p&gt;At the moment we release a new version containing fixes and features about once a week. We have a smart chatbot that lets us release to Maven Central with only one comment. See how the latest release went &lt;a href="https://github.com/decorators-squad/eo-yaml/issues/319"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To conclude, we hope we have provided a good overview of the product and hope to see as many users try it as possible. Feel free to open a Github Issue for any problem, question or feature request you may have, we'll try to help as fast as possible.&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
      <category>yaml</category>
    </item>
  </channel>
</rss>
