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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:55:01+00:00 2026-06-13T08:55:01+00:00

I am implementing simple RESTful webservice using Jersey API. My server project is hosted

  • 0

I am implementing simple RESTful webservice using Jersey API. My server project is hosted on Apache Tomcat ver 6.0 and it contains asm-3.0.jar, jersey-bundle-1.9.1.jar and jsr311-api-1.1.1.jar.

I have two resource classes. One is UserItemsResource which is intended to represent collection of UserItem objects. The other one is UserItemResource which represents a single UserItem resource.

Below is code for UserItemsResource class:

@Path("/useritems")
public class UserItemsResource {

    @Context
    UriInfo uriInfo;

    @Context
    Request request;

    @Path("{userId}")
    public UserItemResource getUserItemResource(@PathParam("userId") long userId) {
        return new UserItemResource(uriInfo, request, userId);
    }
}

The UserItemResource class:

public class UserItemResource {
    @Context
    UriInfo uriInfo;

    @Context
    Request request;

    private long userId;

    public UserItemResource(UriInfo uriInfo, Request request, long userId) {
        this.uriInfo = uriInfo;
        this.request = request;
        this.userId = userId;
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public UserItem getUserItem() {
        return new UserItem(userId, 'M', "Pawan");
    }
}

And the UserItem class:

@XmlRootElement
public class UserItem {
    private long userId;
    private char sex;
    private String displayName;

    public UserItem() {

    }

    public UserItem(long userId, char sex, String displayName) {
        this.userId = userId;
        this.sex = sex;
        this.displayName = displayName;
    }

    public long getUserId() {
        return userId;
    }

    public char getSex() {
        return sex;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }
}

When I invoke the resource (like /useritems/101), I am getting following response from server.

HTTP/1.1 200 OK
Date: Wed, 24 Oct 2012 11:30:35 GMT
Transfer-Encoding: chunked
Content-Type: application/json
Server: Apache-Coyote/1.1

{
  "displayName": "Pawan",
  "sex": "77",
  "userId": "101"
}

You can see that the value for “sex” attribute is generated as “77”, which is ASCII equivalent of character ‘M’. I believe this should come as “M” only, so that my client code can successfully parse it back to ‘M’. I am using Jackson API (ver 2.0.2) to parse the json entity in the server response back to object of UserItem class.

Am I missing something? Or is this a bug?

  • 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-13T08:55:02+00:00Added an answer on June 13, 2026 at 8:55 am

    Jersey supports few JSON notations and each one of them has a slightly different convention on how the resulting JSON should look like. You can see the difference between notations in this JavaDoc. The default one is MAPPED which put quotes around numbers in JSON output as you’ve already found out.

    There are two things you can do:

    • turn on the Jackson POJO support which uses the Jackson library to create JSON output (maybe this would be a better option if you’re using Jackson on the client side as well). There is also an example how to use it – JacksonJsonProvider.
    • use NATURAL JSON notation which handles numbers as you’d expect. To do this you need to provide a custom ContextResolver and register it in your application. Examples how to achieve this can be found in Jersey User Guide (JSON Support – Configuration Options) or in one of the samples json-from-jaxb (see JAXBContextResolver).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I'm implementing a simple chat in .NET using Rx on the basis of this
I'm implementing a simple Graph library for my uni project and since this is
I am implementing a simple audit log functionality using hibernate event listeners. I wanted
I'm developing a RESTful API for a client. The problem is, he's using a
I'm implementing a simple proof of concept Telnet server in C# and telnet to
I'm implementing a simple password store using Blowfish. All was fine until I tried
I'm implementing a simple REST service with the WCF Web API and attempt to
I'm implementing a simple client-server program. Some parts of the i wrote is: int
I am implementing a simple thread pool mechanism for my ubuntu server (for my

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.