Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

3.9K
Views
Envíe json con Ajax a RestController de Spring Boot (Error de tipo de contenido 'application/json;charset=UTF-8' no compatible)

Tengo un problema para enviar datos JSON al método de RestController. Recibí este tipo de error que se muestra a continuación.

 error: "Unsupported Media Type" message: "Content type 'application/json;charset=UTF-8' not supported"

Aquí está mi método relacionado en js.

 function postQuestion() { url = contextPath + "post_question/" + productId; question = $("#question").val(); jsonData = {questionContent: question}; $.ajax({ type: 'POST', url: url, beforeSend: function(xhr) { xhr.setRequestHeader(csrfHeaderName, csrfValue); }, data: JSON.stringify(jsonData), contentType: 'application/json' }).done(function(response) { $("#modalDialog").on("hide.bs.modal", function(e) { $("#question").val(""); }); ..... }).fail(function() { ..... }); }

Aquí está mi método definido en RestController.

 @PostMapping(value="/post_question/{productId}") public ResponseEntity<?> postQuestion(@RequestBody Question question, @PathVariable(name = "productId") Integer productId, HttpServletRequest request) throws ProductNotFoundException, IOException { LOGGER.info("QuestionRestController | postQuestion is called"); LOGGER.info("QuestionRestController | postQuestion | question : " + question.getQuestionContent()); LOGGER.info("QuestionRestController | postQuestion | productId : " + productId); Customer customerUser = authenticationControllerHelperUtil.getAuthenticatedCustomer(request); LOGGER.info("QuestionRestController | postQuestion | customerUser : " + customerUser.getFullName()); if (customerUser == null) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } questionService.saveNewQuestion(question, customerUser, productId); return new ResponseEntity<>(HttpStatus.OK); }

Aquí está mi entidad de pregunta que se muestra a continuación.

 @Entity @Table(name = "questions") @Getter @Setter public class Question implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column(name = "question") private String questionContent; }

Incluso si definí dataType:'json' en js o consumes={"application/json;charset=UTF-8"} en el método de RestController, todo esto no pudo ayudarme a solucionar mi problema.

¿Cómo puedo arreglarlo?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!