'A problem with getting response from Spring Boot after a fetch request

I have a very annoying issue. I have this Javascript code inside a React component:

let entityJson = JSON.stringify(entityObject); 
fetch("http://localhost:8080/add", {
    method: "POST",
    mode: "no-cors",
    headers: { "Content-Type" : "application/json charset=UTF-8"},
    body: entityJson
}).then(data => console.log(data));

This is sending a request to the follow function in an Spring Boot Rest controller:

@PostMapping(produces = "application/json")
public AddEntityResponse newEntity(@RequestBody String person, HttpServletResponse response) {

    AddEntityResponse respons = new AddEntityResponse(0,0);
    Gson jsonReader = new Gson();
    
    try{
        Person newPerson = jsonReader.fromJson(person, Person.class);
        personStore.addPerson(newPerson);
        respons.setStatus(1);
        respons.setId(newPerson.getId());
    }catch(Exception e){
        System.out.println(e.toString());
    }
    
    return respons;
}

But regardless of what I add, this is the request I am getting an empty response, so I guess the issue is in the Java code. I am learning this stuff now, started today so sorry if this seem a bit stupd.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source