Create a JSON object to post in Spring Boot tests
<p>I want to write basic test to execute a POST request on a /users URL with JSON payload to create a user. I cannot find how to convert a new object to JSON, and so far have this much, it's obviously wrong but explains the purpose:</p>

<pre><code>@Test public void createUser() throws Exception {
    String userJson = new User("My new User", "myemail@gmail.com").toJson();
    this.mockMvc.perform(post("/users/").contentType(userJson)).andExpect(status().isCreated());
</code></pre>