Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:29:23+00:00 2026-05-23T02:29:23+00:00

The goal is to create a rest-full web service using JAX-RS that will selectively

  • 0

The goal is to create a rest-full web service using JAX-RS that will selectively return the result either in json or xml format, depending on the user request. For example, if the user issues a GET request in the following fashion the results will be returned in json format:

http://api.myurl.com/order/1234.json

Similarly, if the user issues a get in the following request, the results will be returned in xml format:

http://api.myurl.com/order/123.xml

I don’t want to use request parameters to do this (i.e. http://api.myurl.com/order/123?format=json). Using the .json or .xml post-fix seems more intuitive to me.

What would be the best strategy for doing this using the JAX-RS api?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:29:24+00:00Added an answer on May 23, 2026 at 2:29 am

    One way would be to use @Path annotations more thoroughly:

    @GET
    @Path("/order/{id}.xml")
    @Produces("application/xml")
    public Order getOrderAsXML(@PathParam("id") int id) {
        return realGetOrder(id);
    }
    
    @GET
    @Path("/order/{id}.json")
    @Produces("application/json")
    public Order getOrderAsJSON(@PathParam("id") int id) {
        return realGetOrder(id);
    }
    
    private Order realGetOrder(int id) {
        // ...
    }
    

    However I’d be inclined to have a single method serving up both and let the client and supporting JAX-RS framework use content negotiation to decide the serialization method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying create a service that will return results of a OLAP cube
My goal is to create a validated IP address field that will be validated
High Level Goal: Create a single Maven Web Application project that can be used
My goal is to create a version of the app that will expire after
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
I'm trying to create a REST service which shows/adds/deletes/edits soccer data in a database.
My goal is to create an animation with the YUI Animation Utility that does
My goal is to create some kind of swing component that can do two
My goal is to create a simple Win32 Console application that uses HunSpell to
My goal is to create a map of maps so that I can retrieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.