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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:21:28+00:00 2026-06-15T07:21:28+00:00

I have a problem with parsing JSON to Date object. I use Jersey 1.14,

  • 0

I have a problem with parsing JSON to Date object.

I use Jersey 1.14, Tomcat 7.

My Resource class:

    @Path("/user")
    @Produces(MediaType.APPLICATION_JSON)
    public class UserResource {
        @Path("/~/update")
        @POST
        @Consumes(MediaType.APPLICATION_JSON)
        public Response updateUser(User user) {
            // There are update in DB
            // but Date field always null
            return Response.ok().build();
        }
        @Path("/~/get")
        @GET
        public User getUser() {
            // There are I fetch User from DB
            // Works fine, User instance returns in correct JSON
            return user;
        }

    }

My Model:

    @XmlAccessorType(XmlAccessType.NONE)
    @XmlRootElement(name = "user")
    public class User {
        @XmlElement(name = "name")
        private String name;
        @XmlElement(name = "myDate")
        @XmlJavaTypeAdapter(DateAdapter.class)
        private Date myDate;
        // Getters and Setters
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Date getMyDate() {
            return myDate;
        }
        public void setMyDate(Date myDate) {
            this.myDate = myDate;
        }
    }

My XmlAdapter for Date class:

    public class DateAdapter extends XmlAdapter<String, Date> {

        private static final SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd");

        @Override
        public String marshal(Date v) {
            return dateFormat.format(v);
        }

        @Override
        public Date unmarshal(String v) {
            try {
                return dateFormat.parse(v);
            } catch (ParseException e) {
                throw new WebApplicationException();
            }
        }
    }

Why in my POST method always null Date field?
This JSON I am trying to send:

{"name":"Peter","myDate":"1988-05-31"}

P.S. sorry for my bad English.

UPD.
My client code:

    public class Tester {

        public static void main(String... args) throws FileNotFoundException, JSONException {

            Client c = Client.create();
            WebResource r = c.resource("http://localhost:8080/myapp/user/~/get");
            ClientResponse resp = r.get(ClientResponse.class);
            JSONObject entity = resp.getEntity(JSONObject.class);
            entity.remove("myDate");
            entity.put("myDate", "1988-05-31");
            r = c.resource("http://localhost:8080/myapp/user/~/update");
            resp = r.entity(entity, MediaType.APPLICATION_JSON).post(ClientResponse.class);
            entity = resp.getEntity(JSONObject.class);
            System.out.println(entity);
        }
    }     

UPD 2.

I found a very stupid mistake in my app.
Instead java.util.Date I used java.sql.Date in my Model class 🙁
Thats why Date field always was null.

  • 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-15T07:21:30+00:00Added an answer on June 15, 2026 at 7:21 am

    Your server code are right. The error is in your client code:

    resp = r.entity(entity, MediaType.APPLICATION_JSON).post(ClientResponse.class);
    

    should be:

    resp = r.type(MediaType.APPLICATION_JSON).post(ClientResponse.class,entity);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with JSON parsing. When I hit URL, I've got JSON
I have a problem parsing the array of objects from the JSON result. [
I have a small problem parsing json response because it constantly keeps on getting
Hello friends i am having problem in parsing jSON web services data I have
I have a problem with parsing my JSon Data in an Android application. I
I have a problem with parsing a JSON result. This is what I get
I have a problem while parsing a json with Gson. here is my code:
I'm having a problem on parsing a JSON from Google Places. I have the
I'm manually parsing Json objects using java and I have a problem with urls.
Hi i have some problem parsing the json in IOS. This is the json

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.