Home > Java > javaTutorial > body text

Why am I getting a 415 Unsupported Media Type Error When POSTing JSON to a Jersey REST Service?

Susan Sarandon
Release: 2024-10-30 17:27:03
Original
255 people have browsed it

Why am I getting a 415 Unsupported Media Type Error When POSTing JSON to a Jersey REST Service?

POST to Jersey REST Service Encounters 415 Error: Unsupported Media Type

Consider the situation where you encounter a HTTP 415 error when attempting to POST JSON data to a Jersey-powered REST service. This issue may arise in a standard setup involving a HelloWorld.java resource with GET and POST annotations and a request formatted in Postman with an 'application/json' header.

Resolving the Error

The error indicates that the Jersey distribution does not inherently support JSON/POJO conversions. To resolve this, additional dependencies must be introduced to enable JSON processing. These include:

  • jersey-media-json-jackson-2.17
  • jackson-jaxrs-json-provider-2.3.2
  • jackson-core-2.3.2
  • jackson-databind-2.3.2
  • jackson-annotations-2.3.2
  • jackson-jaxrs-base-2.3.2
  • jackson-module-jaxb-annotations-2.3.2
  • jersey-entity-filtering-2.17

Implementing the Solution with Maven

Using Maven, the following dependency will incorporate all the necessary dependencies:

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.17</version>
</dependency>
Copy after login

Adapting the Solution to Other Jersey Versions

For users utilizing Jersey versions other than 2.17, refer to the Jersey documentation to identify the required transitive dependency versions. Focus particularly on the Jackson version, as the dependency listed here employs Jackson 2.3.2, ensuring compatibility with this specific version.

The above is the detailed content of Why am I getting a 415 Unsupported Media Type Error When POSTing JSON to a Jersey REST Service?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!