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 3844954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:10:11+00:00 2026-05-19T16:10:11+00:00

I have a restful web service, and the response is: { cities: [{ id:

  • 0

I have a restful web service, and the response is:

{
    "cities": [{
        "id": "1",
        "name": "City 01",
        "state": "A1"
    }, {
        "id": "2",
        "name": "City 02",
        "state": "A1"
    }]
}

But I want this:

{
    [{
        "id": "1",
        "name": "City 01",
        "state": "A1"
    }, {
        "id": "2",
        "name": "City 02",
        "state": "A1"
    }]
}

How I can configure JAX-RS to produces JSON without root node using only JAX-RS feature, and not implementation specific feature? My code needs to be portable across any appserver.

  • 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-19T16:10:12+00:00Added an answer on May 19, 2026 at 4:10 pm

    I had the same problem with Glassfish v3. I found this behavior depends on the JAX-RS implementation and switching to Codehaus’ Jackson JAX-RS implementation solved the problem for me.

    If you’re using Glassfish as well, then you can solve the problem by adding org.codehaus.jackson.jaxrs to your war as well as to the WEB-INF/web.xml configuration as follows:

    <!-- REST -->
    
    <servlet>
      <servlet-name>RESTful Services</servlet-name>
      <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
      <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
        <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
      </init-param>
      <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>you.service.packages;org.codehaus.jackson.jaxrs</param-value>
        <!-- NOTE: The last element above, org.codehaus.jackson.jaxrs, replaces the default
           JAX-RS processor with the Codehaus Jackson JAX-RS implementation. The default
           JAX-RS processor returns top-level arrays encapsulated as child elements of a
           single JSON object, whereas the Jackson JAX-RS implementation return an array.
        -->
      </init-param>
      <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
      <servlet-name>RESTful Services</servlet-name>
      <url-pattern>/your/rest/path/*</url-pattern>
    </servlet-mapping>
    

    Alternatively, you might be able to simply intercept the response in the client:

    function consumesCity(json) {
       ...
    }
    

    Replace

    ... consumesCity(json) ...
    

    with

    function preprocess(json) {
        return json.city;
    }
    
    ... consumesCity(preprocess(json)) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a restful web service which can deal with DTOs in json format
I have a RESTful web service that returns JSON-serialized data. It can successfully serialize
I have a RESTful web service running on Jersey (GlassFish 3.1.1). This one's a
I have a RESTful web service deployed at http://example.com/v1/SomeResource . One day, a new
I have a ReSTful web service which needs to parse locale-sensitive data from the
I have created a RESTful PHP web service using Lithium which contains comments, each
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
I have a web service site that is restful enabled, so other websites/ajax script
We have a RESTful web service with a URI pattern like: /orders/ /orders/1 /orders/1/changelog
I have a RESTFULL type of web service which can return both xml and

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.