<?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>Forem: hairshkumar</title>
    <description>The latest articles on Forem by hairshkumar (@codebooker).</description>
    <link>https://forem.com/codebooker</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%2F790066%2F240bbbd7-c7b0-41d6-a16c-1ba417b6c597.png</url>
      <title>Forem: hairshkumar</title>
      <link>https://forem.com/codebooker</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codebooker"/>
    <language>en</language>
    <item>
      <title>Useful tutorial and blog post link for developer</title>
      <dc:creator>hairshkumar</dc:creator>
      <pubDate>Sun, 11 Jun 2023 16:55:10 +0000</pubDate>
      <link>https://forem.com/codebooker/useful-tutorial-and-blog-post-link-for-developer-4eli</link>
      <guid>https://forem.com/codebooker/useful-tutorial-and-blog-post-link-for-developer-4eli</guid>
      <description>&lt;p&gt;ElasticSearch API tutorial with java example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/02/inserting-data-into-elasticsearch-with.html"&gt;https://codebooker.blogspot.com/2023/02/inserting-data-into-elasticsearch-with.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/01/elasticsearch-get-list-of-all-indices.html"&gt;https://codebooker.blogspot.com/2023/01/elasticsearch-get-list-of-all-indices.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/01/elastic-java-client-create-index-with.html"&gt;https://codebooker.blogspot.com/2023/01/elastic-java-client-create-index-with.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/01/elasticsearch-kibana-installation-and.html"&gt;https://codebooker.blogspot.com/2023/01/elasticsearch-kibana-installation-and.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python script to automate grafana bulk import and export&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/12/grafana-bulk-import-dashboard-api.html"&gt;https://codebooker.blogspot.com/2022/12/grafana-bulk-import-dashboard-api.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/12/how-to-bulk-export-grafana-dashboard-at.html"&gt;https://codebooker.blogspot.com/2022/12/how-to-bulk-export-grafana-dashboard-at.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spring boot tutorial&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/08/create-custom-query-in-spring-data-jpa.html"&gt;https://codebooker.blogspot.com/2022/08/create-custom-query-in-spring-data-jpa.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/07/spring-boot-jdbctemplate-curd-operation.html"&gt;https://codebooker.blogspot.com/2022/07/spring-boot-jdbctemplate-curd-operation.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/06/controller-vs-restcontroller-in-spring.html"&gt;https://codebooker.blogspot.com/2022/06/controller-vs-restcontroller-in-spring.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/03/explore-spring-testresttemplate-for.html"&gt;https://codebooker.blogspot.com/2022/03/explore-spring-testresttemplate-for.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/01/injecting-yaml-properties-to-java.html"&gt;https://codebooker.blogspot.com/2022/01/injecting-yaml-properties-to-java.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/12/jpa-one-to-many-and-many-to-one.html"&gt;https://codebooker.blogspot.com/2021/12/jpa-one-to-many-and-many-to-one.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/12/spring-boot-jpa-association-mapping.html"&gt;https://codebooker.blogspot.com/2021/12/spring-boot-jpa-association-mapping.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/12/spring-boot-reduce-boilerplate-code.html"&gt;https://codebooker.blogspot.com/2021/12/spring-boot-reduce-boilerplate-code.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/11/yaml-json-pojo-model-conversion-in.html"&gt;https://codebooker.blogspot.com/2021/11/yaml-json-pojo-model-conversion-in.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/11/spring-boot-mail-sender-tutorial-email.html"&gt;https://codebooker.blogspot.com/2021/11/spring-boot-mail-sender-tutorial-email.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/10/spring-boot-jpa-integration-with-sqlite.html"&gt;https://codebooker.blogspot.com/2021/10/spring-boot-jpa-integration-with-sqlite.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/09/bean-validation-in-spring-boot-complete.html"&gt;https://codebooker.blogspot.com/2021/09/bean-validation-in-spring-boot-complete.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/09/spring-boot-rest-api-project-example.html"&gt;https://codebooker.blogspot.com/2021/09/spring-boot-rest-api-project-example.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/07/code-generation-using-swagger-codegen.html"&gt;https://codebooker.blogspot.com/2021/07/code-generation-using-swagger-codegen.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/07/designing-spring-boot-rest-api-swagger.html"&gt;https://codebooker.blogspot.com/2021/07/designing-spring-boot-rest-api-swagger.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/04/spring-boot-security-custom-login-page.html"&gt;https://codebooker.blogspot.com/2021/04/spring-boot-security-custom-login-page.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/07/spring-java-rule-engine-jeasy-rule.html"&gt;https://codebooker.blogspot.com/2021/07/spring-java-rule-engine-jeasy-rule.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Java interview coding round questions and solutions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/03/balanced-parentheses-brackets-solution.html"&gt;https://codebooker.blogspot.com/2022/03/balanced-parentheses-brackets-solution.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/03/java-interview-coding-problems-and.html"&gt;https://codebooker.blogspot.com/2022/03/java-interview-coding-problems-and.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/02/top-searching-algorithm-in-data.html"&gt;https://codebooker.blogspot.com/2022/02/top-searching-algorithm-in-data.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/01/top-10-java-technical-interview.html"&gt;https://codebooker.blogspot.com/2022/01/top-10-java-technical-interview.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Java related tutorial&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2020/12/java-8-stream-tutorial-java-8-stream.html"&gt;https://codebooker.blogspot.com/2020/12/java-8-stream-tutorial-java-8-stream.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/05/java-8-stream-api-map-vs-flatmap-with.html"&gt;https://codebooker.blogspot.com/2022/05/java-8-stream-api-map-vs-flatmap-with.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/11/java-simple-date-formatting-and.html"&gt;https://codebooker.blogspot.com/2022/11/java-simple-date-formatting-and.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/10/convert-string-to-date-localdate.html"&gt;https://codebooker.blogspot.com/2022/10/convert-string-to-date-localdate.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/09/mapstruct-library-automatically.html"&gt;https://codebooker.blogspot.com/2022/09/mapstruct-library-automatically.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/08/five-solid-principles-in-java-with.html"&gt;https://codebooker.blogspot.com/2022/08/five-solid-principles-in-java-with.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/02/learn-how-to-parse-csv-file-with.html"&gt;https://codebooker.blogspot.com/2022/02/learn-how-to-parse-csv-file-with.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2020/11/what-is-and-how-functional-interface.html"&gt;https://codebooker.blogspot.com/2020/11/what-is-and-how-functional-interface.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Javascript game developement mini project&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2021/04/develop-space-shooter-game-using.html"&gt;https://codebooker.blogspot.com/2021/04/develop-space-shooter-game-using.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2020/11/build-simple-javascript-snake-game-with.html"&gt;https://codebooker.blogspot.com/2020/11/build-simple-javascript-snake-game-with.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/12/how-to-highlight-code-syntax-snippet.html"&gt;https://codebooker.blogspot.com/2022/12/how-to-highlight-code-syntax-snippet.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ionic tutorial&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/03/ionic-native-app-dark-and-light-mode.html"&gt;https://codebooker.blogspot.com/2022/03/ionic-native-app-dark-and-light-mode.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2020/11/ionic-framework-google-admob.html"&gt;https://codebooker.blogspot.com/2020/11/ionic-framework-google-admob.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GraphQL tutorial&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/01/graphql-mutation-and-error-handling.html"&gt;https://codebooker.blogspot.com/2022/01/graphql-mutation-and-error-handling.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2022/01/create-graphql-api-in-spring-boot.html"&gt;https://codebooker.blogspot.com/2022/01/create-graphql-api-in-spring-boot.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>news</category>
      <category>java</category>
    </item>
    <item>
      <title>Hands on search engine in Java using Elastic search</title>
      <dc:creator>hairshkumar</dc:creator>
      <pubDate>Sun, 04 Jun 2023 13:11:00 +0000</pubDate>
      <link>https://forem.com/codebooker/hands-on-search-engine-in-java-using-elastic-search-2a6g</link>
      <guid>https://forem.com/codebooker/hands-on-search-engine-in-java-using-elastic-search-2a6g</guid>
      <description>&lt;h2&gt;
  
  
  What is Elasticsearch and where is it used?
&lt;/h2&gt;

&lt;p&gt;If you're looking for a powerful search engine and data visualization tool, then you need to install Elasticsearch and Kibana. Elasticsearch is a distributed, Restful search and analytics engine that helps you find the right information quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Kibana and where is it used?
&lt;/h2&gt;

&lt;p&gt;Kibana is a data visualization tool that lets you see your data in creative and exciting ways. Having both of these tools installed can be extremely beneficial for anyone who wants to be able to quickly find and visualize their data.&lt;/p&gt;

&lt;p&gt;Steps to download and install Elastic search and kibana &lt;a href="https://codebooker.blogspot.com/2023/01/elasticsearch-kibana-installation-and.html"&gt;Integrate ElasticSearch with kibana&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some of the term used in elastic search.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Index - similar to table which store record(document) in it.&lt;/li&gt;
&lt;li&gt;Document - JSON object stored in index &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let create a index and insert documents into it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/01/elastic-java-client-create-index-with.html"&gt;Index creation and their settings in elastic searh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/02/inserting-data-into-elasticsearch-with.html"&gt;Insert documents into elastic index from Spring boot API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codebooker.blogspot.com/2023/01/elasticsearch-get-list-of-all-indices.html"&gt;Fetching documents from index by building query&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Detailed post with examples are available in &lt;a href="https://codebooker.blogspot.com/"&gt;codebooker&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>springboot</category>
      <category>webdev</category>
      <category>blog</category>
    </item>
    <item>
      <title>Map Struct Tutorial - autogenerate mapper code in java</title>
      <dc:creator>hairshkumar</dc:creator>
      <pubDate>Sun, 02 Oct 2022 07:07:43 +0000</pubDate>
      <link>https://forem.com/codebooker/map-struct-tutorial-autogenerate-mapper-code-in-java-2je</link>
      <guid>https://forem.com/codebooker/map-struct-tutorial-autogenerate-mapper-code-in-java-2je</guid>
      <description>&lt;p&gt;Normal mapping&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;Mapper&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;Employee&lt;/span&gt; &lt;span class="nf"&gt;toEmployee&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EmployeeDTO&lt;/span&gt; &lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="n"&gt;employee&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;Employee&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setJobTitle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getJobTitle&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setJoinedDate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getJoinedDate&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setMobileNo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMobileNo&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setDepartment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDepartment&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setSalary&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getSalary&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;employee&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;what is mapstruck?&lt;/p&gt;

&lt;p&gt;MapStruct is a code generator that greatly simplifies the implementation of mappings between Java models and DTO. Using Mapstruck we don’t have to long mapper code instead simply we need to say source and destination class.&lt;/p&gt;

&lt;p&gt;MapStruck automatically generates mapper code which maps fields based on name from source to destination class also we can pass custom mapping for field.&lt;/p&gt;

&lt;p&gt;mapstruck maven dependency&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;org.mapstruct.version&amp;gt;&lt;/span&gt;1.5.2.Final&lt;span class="nt"&gt;&amp;lt;/org.mapstruct.version&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.mapstruct&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mapstruct&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${org.mapstruct.version}&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you are using Lombok to reduce boilerplate cod in entity or DTO class then add below in pom.xml&lt;/p&gt;

&lt;p&gt;How to create a Mapper in mapstruck?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;build&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;plugins&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.apache.maven.plugins&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;maven-compiler-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;3.8.1&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;source&amp;gt;&lt;/span&gt;1.8&lt;span class="nt"&gt;&amp;lt;/source&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;target&amp;gt;&lt;/span&gt;1.8&lt;span class="nt"&gt;&amp;lt;/target&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;annotationProcessorPaths&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;path&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.projectlombok&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;lombok&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${org.projectlombok.version}&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;/path&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;path&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.mapstruct&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mapstruct-processor&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${org.mapstruct.version}&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;/path&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;/annotationProcessorPaths&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/plugins&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/build&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an interface and annotate with &lt;strong&gt;@Mapper&lt;/strong&gt;. Now let's define a method. The method parameter acts as source and method return type acts as Target. MapStruck will map source fields to target fields if they have the same field name.&lt;/p&gt;

&lt;p&gt;Mapping fields with same name&lt;/p&gt;

&lt;p&gt;By default, MapStruck maps fields by name if source and target have fields with same name then mapper maps the field. The EmployeeDTO and Employee both classes have the same property names.&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;@Mapper&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;componentModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"spring"&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;interface&lt;/span&gt; &lt;span class="nc"&gt;EmployeeMapper&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="nf"&gt;toEmployee&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EmployeeDTO&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&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 componentModel = “spring” define this mapper as spring bean which we can autowire in our application.&lt;/p&gt;

&lt;p&gt;The generated class code will look like below the source and target classes both having the same property names.&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;@Component&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;EmployeeMapperImpl&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;EmployeeMapper&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;Employee&lt;/span&gt; &lt;span class="nf"&gt;toEmployee&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EmployeeDTO&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="n"&gt;employee&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;Employee&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setDepartment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDepartment&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setGender&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getGender&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setId&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setJobTitle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getJobTitle&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setJoinedDate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getJoinedDate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setMobileNo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMobileNo&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setSalary&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getSalary&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;employee&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;Mapping fields with different name&lt;/p&gt;

&lt;p&gt;In most of the cases, the source and target classes will not have same field names so now how to map these fields for this we have @Mapping annotation which take the target field name and soruce field name map these field. We can give custom mapping logic for fields in @Mapping annotation.&lt;/p&gt;

&lt;p&gt;@Mappings takes group of @Mapping annotation if there is more mapping logic than its better give them inside @Mappings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface EmployeeMapper {

    @Mappings({
        @Mapping(target = "jobTitle", source = "title"),
        @Mapping(target = "joinedDate", source = "startingdate")
    })
    Employee toEmployee(EmployeeDTO employeeDTO);

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

&lt;/div&gt;



&lt;p&gt;Mapping nested beans fields&lt;/p&gt;

&lt;p&gt;Here we will see how we can map nested object fields if you see example below the Employee class has Personal object which has name, gender, age and Address object.&lt;/p&gt;

&lt;p&gt;We have to give full path to the field example personal.address.streetaddress in target, so mapper will search for streetaddress inside address in personal object.&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;@Mappings&lt;/span&gt;&lt;span class="o"&gt;({&lt;/span&gt; 
    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"personal.name"&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="s"&gt;"firstName"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"personal.gender"&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="s"&gt;"gender"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; 
    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"personal.age"&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="s"&gt;"age"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"personal.address.streetaddress"&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="s"&gt;"dto.primaryAddr.line1"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"personal.address.city"&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="s"&gt;"dto.primaryAddr.city"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"personal.address.postalcode"&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="s"&gt;"dto.primaryAddr.postalCode"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;span class="o"&gt;})&lt;/span&gt;
&lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="nf"&gt;toEmployee&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EmployeeDTO&lt;/span&gt; &lt;span class="n"&gt;dto&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mapping custom method&lt;/p&gt;

&lt;p&gt;In some cases it can be required to manually implement a specific mapping from one type to another which can’t be generated by MapStruct. One way to handle this is to implement the custom method on another class which then is used by mappers generated by MapStruct&lt;/p&gt;

&lt;p&gt;Define java 8 default method in the interface and provide the implementation. We use @Named to name the method.&lt;/p&gt;

&lt;p&gt;In the @Mapping define the source and target, give the @Named method name in the qualifiedByName attributes so the mapstruck will generate the code and call the default method&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="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.example.graphql.mapstruck&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.ArrayList&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.List&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Mapper&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;componentModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"spring"&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;interface&lt;/span&gt; &lt;span class="nc"&gt;EmployeeMapper&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Mapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"primaryAddr"&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="s"&gt;"personal.address"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;qualifiedByName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"addressdto"&lt;/span&gt; &lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;EmployeeDTO&lt;/span&gt; &lt;span class="nf"&gt;toEmployeeDto&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="nd"&gt;@Named&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"addressdto"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;PrimaryAddr&lt;/span&gt; &lt;span class="nf"&gt;composeAddress&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;PrimaryAddr&lt;/span&gt; &lt;span class="n"&gt;primaryAddr&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;PrimaryAddr&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;primaryAddr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setLine1&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getStreetaddress&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;primaryAddr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setCity&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getCity&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;primaryAddr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setPostalCode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPostalcode&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;primaryAddr&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;Let see how mapstruck have generated the mapper code for the above custom method.The generated mapper code internally call our custom method for mapping address.&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;EmployeeMapperImpl&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;EmployeeMapper&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;EmployeeDTO&lt;/span&gt; &lt;span class="nf"&gt;toEmployeeDto&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;EmployeeDTO&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&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;EmployeeDTO&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setPrimaryAddr&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;composeAddress&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employeePersonalAddress&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employee&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;employeeDTO&lt;/span&gt;&lt;span class="o"&gt;;&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;Address&lt;/span&gt; &lt;span class="nf"&gt;employeePersonalAddress&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="nc"&gt;Personal&lt;/span&gt; &lt;span class="n"&gt;personal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPersonal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;personal&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="nc"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;personal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAddress&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&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="kc"&gt;null&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;address&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;



</description>
      <category>tutorial</category>
      <category>java</category>
      <category>springboot</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Integrating GraphQL in Spring boot Project guideline </title>
      <dc:creator>hairshkumar</dc:creator>
      <pubDate>Tue, 11 Jan 2022 08:15:28 +0000</pubDate>
      <link>https://forem.com/codebooker/integrating-graphql-in-spring-boot-project-guideline-4694</link>
      <guid>https://forem.com/codebooker/integrating-graphql-in-spring-boot-project-guideline-4694</guid>
      <description>&lt;p&gt;In this blog, we will learn graphql API in spring boot and see graphql schema, query, etc.&lt;/p&gt;

&lt;p&gt;we are going to implement graphql in the existing spring boot project that we have created in the previous blog spring-boot-JPA-integration-with-SQLite.&lt;/p&gt;

&lt;h2&gt;
  
  
  GraphQL API tutorial in Spring boot
&lt;/h2&gt;

&lt;p&gt;What is GraphQL?&lt;/p&gt;

&lt;p&gt;GraphQL is a query language for API not specific to any database or framework developed by Facebook, GraphQL client uses graphQL query( specific which fields we are looking for in response) to fetch data from the server.&lt;/p&gt;

&lt;p&gt;In GraphQL, the client can get all details in a single request instead of multiple calls to the backend like REST API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Graphql Maven dependency
&lt;/h2&gt;

&lt;p&gt;we need to add the below dependency in the pom.xml file which provides support for creating graphQL API in spring boot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.graphql-java&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;graphql-spring-boot-starter&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;5.0.2&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.graphql-java&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;graphql-java-tools&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;5.2.4&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;!-- GraphiQL --&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.graphql-java&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;graphiql-spring-boot-starter&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;5.0.2&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;By default, the GraphQL Service will be accessible on /graphql URL and will accept POST requests with the GraphQL Payload. If required, you can modify this endpoint in our application.properties file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create GraphQl Schema
&lt;/h2&gt;

&lt;p&gt;First, we need to create a graphql schema that contains the graphql query and object type (similar to class) that return in the response.&lt;/p&gt;

&lt;p&gt;graphQL API tutorial schema diagram&lt;/p&gt;

&lt;p&gt;The graphql server exposes this schema to the graphql client describing the available query and structure of object data (class and their field) based on schema the client creates a query and sends it to the server for execution.&lt;/p&gt;

&lt;p&gt;create a schema.graphqls file inside the src/main/resource folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;schema {
  query: Query
}

type Query {
  getAllEmployee: [Employee]
  getEmployeeById(id: Int): Employee
}

type Employee {
  id: ID
  name: String
  jobTitle: String
  mobileNo: String
  joinedDate: String
  gender: String
  department: Department
  project: Project
}

type Department {
  id: ID
  name: String
}

type Project {
  id: ID
  name: String
}

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

&lt;/div&gt;



&lt;p&gt;Here the Employee, Department, and Project are graphql object types. The [Employee] means an array of employee objects.&lt;/p&gt;

&lt;p&gt;The getAllEmployee and getEmployeeById are queries the client use to fetch object data from the graphql server.&lt;/p&gt;

&lt;p&gt;we can have several separate schema files to organize the schemes, e.g. we can have employee.graphqls, project.graphqls, etc.&lt;/p&gt;

&lt;p&gt;There can be only one query and mutation type describing all operations, if there are separate schema files each containing its own query and mutation then use extend keyword so all queries and mutation are added together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create JPA repository
&lt;/h2&gt;

&lt;p&gt;let's create a JPA repository to get employee details from the SQLite database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.example.graphql.model.Employee;

@Repository
public interface EmployeeRepository extends JpaRepository&amp;lt;Employee, Integer&amp;gt; {

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Query Resolver
&lt;/h2&gt;

&lt;p&gt;Now create a class GraphQLService that implements GraphQLQueryResolver, this class contains the actual implementation of a query defined in the graphql schema. &lt;/p&gt;

&lt;p&gt;The query name defined in schema and method name must be the same. &lt;/p&gt;

&lt;p&gt;Please see the complete post &lt;a href="https://codebooker.blogspot.com/2022/01/create-graphql-api-in-spring-boot.html"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>java</category>
    </item>
  </channel>
</rss>
