2

I have a JavaFX app and a Java server, I am trying to send a post method with a JSON but when I do I get this error from the server

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 middle byte 0x77; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0x77
 at [Source: (PushbackInputStream); line: 1, column: 209] (through reference chain: java.util.ArrayList[0]->pwsztar.edu.pl.project_kino.dto.Film["opis"])]

My post request looks like this

String json = new Gson().toJson(filmsToDelete);
            System.out.println(json);

            var request = new HttpPost("http://localhost:8080/api/v1/removeFilm");
            request.setHeader("Content-type", "application/json;charset=UTF-8");
            request.setEntity(new StringEntity(json));

            HttpResponse response = client.execute(request);
            System.out.println(response.getStatusLine());

The filmToDelete is and arraylist of Film objects. And this is mine controller methond on the server

@PostMapping(path = "removeFilm")
    public void removeFilms(@RequestBody ArrayList<Film> filmsToRemove){
        filmService.printFilms(filmsToRemove);
    }

So what I would like to know is where is the problem, and maybe how can I fix it. If any additional info let me know

1 Answer 1

3

Set the correct encoding on the StringEntity:

request.setEntity(new StringEntity(json, "UTF-8"));
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, that helped, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.