JavaFX write JSON to Rest Service's Outputstram doesn't work
<p>So I have a Rest Service with possibility of adding books. This part looks like this:</p>

<pre><code>@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity&lt;Void&gt; addBook(@RequestBody BookTo book) {
    if (!bookService.findBooksById(book.getId()).isEmpty()) {
        return new ResponseEntity&lt;Void&gt;(HttpStatus.CONFLICT);
    }
    bookService.saveBook(book);
    return new ResponseEntity&lt;Void&gt;(HttpStatus.CREATED);
}
</code></pre>

<p>I wrote JavaFX Rest Service with bookAdd method:</p>

<pre><code>@FXML
private void addButtonAction(ActionEvent event) throws IOException {
    JSONParserImpl parser = new JSONParserImpl();
    LOG.debug("'Add' button clicked");
    final String targetURL = "http://localhost:8080/webstore/add";
    URL restServiceURL = new URL(targetURL);
    HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();
    httpConnection.setDoOutput(true);
    httpConnection.setRequestMethod("POST");
    httpConnection.setRequestProperty("Content-Type", "application/json");

    String jsonString = parser.toJsonString(model.getTitle(),
            model.getAuthor(),
            model.getStatus().toStatusVO());
    LOG.debug("JSONString: " + jsonString);
    OutputStream output = httpConnection.getOutputStream();
    output.write(jsonString.getBytes());
    output.flush(); 
    LOG.debug("Writing JSON finished.");
}
</code></pre>

<p>parser method:</p>

<pre><code>@Override
public String toJsonString(String title, String author, StatusVO status) {
    LOG.debug("Enter toJsonString method.");
    Gson gson = new Gson();
    BookVO book = new BookVO(title, author, status);
    String jsonInString = gson.toJson(book);
    LOG.debug("JSONString in method: " + jsonInString);
    return jsonInString;
}
</code></pre>

<p>BookVO class:</p>

<pre><code>public class BookVO {
private Long id;
private String title;
private String authors;
private StatusVO status;
}
</code></pre>

<p>id is auto generated in rest service.</p>

<pre><code>@Entity
@Table(name = "BOOK")
public class BookEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, length = 50)
private String title;
@Column(nullable = false, length = 200)
private String authors;
@Enumerated(EnumType.STRING)
private BookStatus status;
</code></pre>

<p>When I click addButton LOG.debug tells me that JSON string looks for example like that:</p>

<pre><code>{"title":"bvb","authors":"bvb","status":"FREE"}
</code></pre>

<p>and if I use for example Postman to add a book with POST and url address: <a href="http://localhost:8080/webstore/add" rel="nofollow">http://localhost:8080/webstore/add</a> and exactly this JSONString as a body, it adds a book properly, but my app doesn't. It shows the last log, but the number of books in service is still the same. What's the problem here?</p>