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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:09:36+00:00 2026-06-07T11:09:36+00:00

I have a Mapping Problem using jackson library to convert a Json API callback

  • 0

I have a Mapping Problem using jackson library to convert a Json API callback to a custom Object.

I’ve got my User custom class :

public class User {
    protected String id;
    protected GregorianCalendar registredAt;
    protected String username;
    protected Team team;

    public User() {

    }

    public User(String id, GregorianCalendar registredAt, String username, Team team) {
        this.id = id;
        this.registredAt = registredAt;
        this.username = username;
        this.team = team;
    }

    public User(HashMap<String, Object> attributes) {
        this.id = (String) attributes.get("id");
        this.registredAt = (GregorianCalendar) attributes.get("registredAt");
        this.username = (String) attributes.get("username");
        this.team = (Team) attributes.get("team");
    }
}

Here’s my callback :

{
    id: "4feab37c5600bbd56f000132",
    registredAt: {
        date: "2012-06-27 09:17:15",
        timezone_type: 3,
        timezone: "Europe/Paris"
    },
    username: "John Doe",
    team: {
        id: "4feab37c5600bbd56f000130",
        indice: 1,
        name: "John Doe's Team",
        score: 200
    }
}

Then, I try to init a User object :

// Code from a doInBackground() method of a custom AsyncTask.
URL completePath = new URL(apiBaseURL + "api/user/4feab37c5600bbd56f000132/show");
APIconnection = (HttpURLConnection) completePath.openConnection();
APIconnection.setDoInput(true);
APIconnection.connect();
callbackParser = jsonFactory.createJsonParser(APIconnection.getInputStream());
response = objectMapper.readValue(callbackParser, User.class);
// Catch a JsonMappingException :
Can not deserialize instance of java.util.Calendar out of START_OBJECT token at [Source: org.apache.harmony.luni.internal.net.www.protocol.http.FixedLengthInputStream@4082c7a0; line: 1, column: 33] (through reference chain: classes.models.User["registredAt"])

I think the problem is that the callback registredAt object is a json_encoded PHP \DateTime instance…
Should I change the type of the registredAt Java User object ?
Or does something is missing in my constructor ?

  • 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-07T11:09:38+00:00Added an answer on June 7, 2026 at 11:09 am

    Finally, I made something like this to resolve my problem :

    public User(HashMap<String, Object> attributes) {
        this.id = (String) attributes.get("id");
        HashMap <String, Object> registredAt = (HashMap<String, Object>) attributes.get("registredAt");
        IMDateFormatter formatter = new IMDateFormatter();
        this.registredAt = formatter.getCalendarFromJson((String) registredAt.get("date"));
        [...]
    }
    

    And IMDateFormatter to format my dates in a simple way :

    public class IMDateFormatter extends DateFormat {
        public IMDateFormatter() {
        }
    
        @Override
        public StringBuffer format(Date arg0, StringBuffer arg1, FieldPosition arg2) {
    
            return null;
        }
    
        @Override
        public Date parse(String dateFromJson, ParsePosition arg1) {
    
            return null;
        }
    
        public GregorianCalendar getCalendarFromJson(String dateFromJson) {
            GregorianCalendar calendarFromJson = null;
    
            try {
                GregorianCalendar tmpCalendar = new GregorianCalendar();
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.FRANCE);
                tmpCalendar.setTime(df.parse(dateFromJson));
                calendarFromJson = tmpCalendar;
            }
            catch (NullPointerException NPE) {
                NPE.printStackTrace();
            }
            catch (ParseException PE) {
                PE.printStackTrace();
            }
    
            return calendarFromJson;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem for mapping my servlet with my Java Server Page, using
I have an odd problem with mapping in Vim. I am using an Azerty
Hi I got a problem with mapping my entities. I'm using JPA2 and Hibernate
i have one problem in one-to-many mapping using hibernate. i have 2 classes, Person
I have a problem with the mapping of Oracle Float double precision datatype to
I have a problem with nhibernate mapping. I use the nhibernate 3.2 mapping by
I have a problem which requires a reversable 1:1 mapping of keys to values.
I have NH mapping public class TblContentMap : ClassMap<TblContent> { public TblContentMap() { Table(tbl_content);
I have a class ClassA mapped to TableA. I also have a mapping for
Hi everyone and couchdb pros, I have a mapping setup like such: class Product(BaseModel):

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.