title: How to store JSON file as a JSON datatype in mysql using Hibernate / Spring boot?
body: <p>I've tried several ways of storing a json file in a database but it ends up creating different columns for each entry.</p>
  
  <p>I want to store it as a "json" type in a single column.
  Is it possible?</p>
  
  <p>My json file. </p>
  
  <p>users.json</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Leanne Graham",
      "username": "Bret",
      "email": "Sincere@april.biz",
      "address": {
        "street": "Kulas Light",
        "suite": "Apt. 556",
        "city": "Gwenborough",
        "zipcode": "92998-3874",
        "geo": {
          "lat": "-37.3159",
          "lng": "81.1496"
        }
      },
      "phone": "1-770-736-8031 x56442",
      "website": "hildegard.org",
      "company": {
        "name": "Romaguera-Crona",
        "catchPhrase": "Multi-layered client-server neural-net",
        "bs": "harness real-time e-markets"
      }
    },
  ...
  ]
  </code></pre>
  
  <p>It's a spring-boot application and I've the relevant controllers and services.</p>
  
  <p>In my domain package. (Address and Company are Embeddable classes)</p>
  
  <p>User.java</p>
  
  <pre class="lang-java prettyprint-override"><code>@Data
  @AllArgsConstructor @NoArgsConstructor
  @Entity
  public class User {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
      private String name;
      private String username;
      private String email;
      private String phone;
      private String website;
  
      @Embedded
      private Address address;
  
      @Embedded
      private Company company;
  }
  </code></pre>
  
  <p>The main file (storing in the database)</p>
  
  <p>TypeReference and ObjectMapper are from Jackson</p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  public class JsondbApplication {
      public static void main(String[] args) {
          SpringApplication.run(JsondbApplication.class, args);
      }
  
      @Bean
      CommandLineRunner runner(UserService service) {
          return args -&gt; {
              ObjectMapper mapper = new ObjectMapper();
              TypeReference&lt;List&lt;User&gt;&gt; reference = new TypeReference&lt;List&lt;User&gt;&gt;() {};
              InputStream stream = TypeReference.class.getResourceAsStream("/json/users.json");
              try {
                  List&lt;User&gt; users = mapper.readValue(stream, reference);
                  service.save(users);
                  System.out.println("Saved!");
              } catch (Exception h) {
                  System.out.println("Unable to save! " + h.getMessage());
              }
          };
      }
  
  }
  </code></pre>
  
  <p>in mysql it creates different columns for <code>id, name, username, ...</code></p>
  
  <p>I want to store it in a <strong><em>single column</em></strong> as a <code>json</code> type using spring boot.</p>