DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How To Approach Dependency Management in Java [Video]
  • Is It Okay To Stop Running Your Tests After the First Failure?
  • Understanding Dependencies...Visually!
  • Tornado vs. FastAPI: Why We Made the Switch

Trending

  • Mastering Persistence: Why the Persistence Layer Is Crucial for Modern Java Applications
  • Memory Management in Java: An Introduction
  • Effective Tips for Debugging Complex Code in Java
  • How To Verify Database Connection From a Spring Boot Application
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Jersey Client Dependencies for JAX-RS 2.1

Jersey Client Dependencies for JAX-RS 2.1

If you're looking to make use of a JAX-RS client outside of an enterprise container, you'll need to know the necessary dependencies.

Sebastian Daschner user avatar by
Sebastian Daschner
·
Oct. 18, 17 · Code Snippet
Like (2)
Save
Tweet
Share
23.51K Views

Join the DZone community and get the full member experience.

Join For Free

Jersey is the reference implementation of JAX-RS 2.1. The following Jersey dependencies are required in order to run a JAX-RS 2.1 client with JSON-P and JSON-B mapping outside of an enterprise container.

Jersey client version 2.6 implements the JAX-RS 2.1 API. The following dependencies add the client runtime to a project:

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.26</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
    <version>2.26</version>
</dependency>


If JSON objects should be mapped using JSON-P, the following dependency is required as well:

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-processing</artifactId>
    <version>2.26</version>
</dependency>


This already adds an implementation for JSON-P 1.1, namely Glassfish javax.json.

If JSON objects should be mapped using JSON-B, the following dependency is added instead of or additionally to the previous one:

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-binding</artifactId>
    <version>2.26</version>
</dependency>


This transitively adds the Yasson dependency, the reference implementation of JSON-B.

These dependencies enable the project to use the JAX-RS 2.1 client together with JSON-P or JSON-B binding:

Client client = ClientBuilder.newClient();
WebTarget target = client
        .target("http://localhost:8080/jersey-test/resources/tests");

Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();
JsonArray customers = response.readEntity(JsonArray.class);

response = target.path("123").request(MediaType.APPLICATION_JSON_TYPE).get();
Customer customer = response.readEntity(Customer.class);

...

public class Customer {

    @JsonbTransient
    private long id;
    private String name;

    // getters & setters
}


And for our Gradle users, here is the equivalent of the Maven declarations:

compile 'org.glassfish.jersey.core:jersey-client:2.26'
compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'

compile 'org.glassfish.jersey.media:jersey-media-json-processing:2.26'
compile 'org.glassfish.jersey.media:jersey-media-json-binding:2.26'
Dependency

Published at DZone with permission of Sebastian Daschner. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Approach Dependency Management in Java [Video]
  • Is It Okay To Stop Running Your Tests After the First Failure?
  • Understanding Dependencies...Visually!
  • Tornado vs. FastAPI: Why We Made the Switch

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: