title: Converting a RequestBody json to an Object - Spring Boot
body: <p>I am a begineer in java development but has previous experience on programming languages like PHP and Python. So little confused on how to proceed on spring boot with the development.</p>
  
  <p>I am developing a rest API which has the following request</p>
  
  <pre><code>{
    "key":"value",
    "key1":"value1",
    "platform_settings":[
        {"key":"value"}
    ]
  }
  </code></pre>
  
  <p><strong>What I did</strong></p>
  
  <p>I created a RestController which accepts the http request and created a function for the resource</p>
  
  <pre><code>public Share share(@RequestBody final Share share) { 
          LOGGER.debug("This is the request", share);
          return share; //
  }
  </code></pre>
  
  <p>Question 1 : If it was any other programming language like PHP or Python, there will be helper function which will accept the json request and convert it to object which I can easily work on.</p>
  
  <p>In python it is as simple as </p>
  
  <pre><code>import json
  import requests
  
  response = requests.get(...)
  json_data = json.loads(response.text)
  //can work on json_data anyway I want.
  </code></pre>
  
  <p>But in java, I will have to create a POJO class, or have jackson/JPA entity as dependency which will map the request to a Class (Which I should predefine with the requests).</p>
  
  <p>Is there any better way I can do this? For every request I make, I will have to create a Class which the request can be mapped to and I will have to define the class</p>
  
  <pre><code>Entity
  
  package com.payunow.socialsharemodule.models;
  
  import java.util.Map;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  
  
  import javax.persistence.Id;
  
  
  @Entity
  public class Share {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      private String key;
      private String key1;
      private Map&lt;String,String&gt; platform_settings;
  
      public Share(String name, String description,Map&lt;String,String&gt; platform_settings) {
          this.key = key;
          this.key1 = key1;
          this.platform_settings = platform_settings;
      }
  
      //for JPA
      public Share() {}
  
      public String getKey() {
          return key;
      }
  
      public String getKey1() {
          return key1;
      }
  
      public Map&lt;String,String&gt; getPlatform_settings() {
          return platform_settings;
      }
  
  }
  </code></pre>
  
  <p><strong>For every request I make, I will have to create a class defining all its variables inside. Is this the only way to do this?</strong></p>