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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:04:14+00:00 2026-06-16T01:04:14+00:00

JSON response: { "categories": [{ "id": "1", "category": "category1" }, { "id": "2", "category":

  • 0

JSON response:

{
    "categories": [{
            "id": "1",
            "category": "category1"
        },
        {
            "id": "2",
            "category": "category2"
        }
    ]
}

JSON Jersey service:

@GET
@Produces("application/json")
public List<Categories> GetAllCategories() {
    return CategoriesDAO.getInstance().getAll();
}

I’m using EJB annotation for hibernate mapping and jaxB for deserialising and serialising JSON.

Model:

@Entity
@XmlRootElement
public class Categories {
    /** @pdOid f9032734-7d05-4867-8275-bf10813c3748 */
    @Id
    @GeneratedValue
    private Integer id;
    private String category;

    public Categories() {
        // TODO Add your own initialization code here.
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer newId) {
        this.id = newId;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String newCategory) {
        this.category = newCategory;
    }
} 

Jersey client code:

ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
WebResource r = client.resource("http://tomcat.com/GetAllCategories");
List<Categories> output = r.get(new GenericType<List<Categories>>() {});
 

Exception:

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@cc4364; line: 1, column: 1]
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:564)
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:524)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:696)
    at com.sun.jersey.api.client.WebResource.get(WebResource.java:196)
    at com.fit.test.Json.GetAllKategorijeJson.main(GetAllKategorijeJson.java:34)
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@cc4364; line: 1, column: 1]
    at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:246)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:204)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:194)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2695)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
    at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:554)
    ... 4 more
  • 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-06-16T01:04:15+00:00Added an answer on June 16, 2026 at 1:04 am

    Brate, slusaj… I had the same problem.
    I was building a simple Restful service and JAXB was returning JSON from my JaxB annotated POJO class when GET methods were executed quite well. When my methds were @Consuming JSON (POST, PUT cases) I found out that JAXB had some problems there.

    It’s better to use JACKSON instead JaxB annotations (you’ll find a lot about it googling) when buiilding Jersey / JSON service. The thing is that JAXB doesn’t do well the conversion (deserialization) from JSON to your POJO objects. JAXB with its @XMLRootElement is quite suitable when working with XML, but not JSON.

    This is what I have in web.xml to enable Jackson’s deserialization/serialization of JSON:

    <!--  JAXB works great with XML but with JSON it's much better to use Jackson. Jersey will use Jackson -->
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
    

    Google for .jar file that needs to be included for Jersey to use Jackson…
    Good luck…

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

Sidebar

Related Questions

I am getting json response from this google api service to get reverse geo
i get a JSON response from a web service: {CoverageSearchByLatLongResult:{HasTransmissionAreasWithSignal:true,SwitchOffArea: {OpenForVastApplications:false,SeperateTileSetUrl:http:\/\/myswitch.merged.stage.orchard.net.au\/geodatafiles\/SwitchOffArea\/442b8844-3c05-4548-9424- 4fdafc1f3c62\/Seperate,HASStatus:Future,HASStatement:<p>The Household Assistance
Executive Summary context.Response.Header.Add("Content-Type", "application/json"); gets ignored while context.Response.ContentType = "application/json"; breaks jQuery ajax calls.
How can I convert the following JSON response to a C# object? { "err_code":
when I'm sending JSON response to jqgrid I get undefined message across it and
I am getting a response String from server like below { "name": "Json", "detail":
I'm trying to POST to a web service that is expecting to get JSON
im getting response in json, but this wont parse the json response. what m
I have a json response like: { total: 2, success: true, rows: [ {a1_id:7847TK10,
below is the json response which i'm getting, { day: [Thursday, Friday, Saturday, Sunday],

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.