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

  • Home
  • SEARCH
  • 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 8844231
In Process

The Archive Base Latest Questions

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

I have a structure of objects representing a Questionnaire and I need to serialize

  • 0

I have a structure of objects representing a Questionnaire and I need to serialize to JSON.
One class of the structure is a OpenQuestion and this class use generics with two parameters.
The problem starts when one of types used was Date, the date is serialized wrong, like a long.

Class code:

public class OpenQuestion <valueType,validationType> extends AbstractQuestion implements    Serializable {
    private valueType value;
    private validationType minValue;
    private validationType maxValue;
    ...
}

I saw how to serialize a date in a hash map if the hash map always uses a Date, but in this case I use the class with String, Integer or Date.

Any idea to solve it?
Thanks

  • 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-14T11:26:05+00:00Added an answer on June 14, 2026 at 11:26 am

    As pointed out by @MiserableVariable, Jackson serializes (most) date fields as (numeric long) timestamps by default. You can override this behavior in a number of ways.

    If using your own instance of ObjectMapper, override a property to write dates as ISO-8601:

    objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    

    If using your own instance of ObjectMapper, to have dates written in your own custom format:

    objectMapper.setDateFormat(myDateFormat); // 1.8 and above
    objectMapper.getSerializationConfig().setDateFormat(myDateFormat); // for earlier versions (deprecated for 1.8+)
    

    To leave the default serialization behavior for most fields, but override it for certain fields on certain objects, use a custom serializer:

    public class MyBean implements Serializable {
        private Date postDate;
    
        // ... constructors, etc
    
        @JsonSerialize(using = MyCustomDateSerializer.class)
        public Date getPostDate() {
            return postDate;
        }
    }
    
    public class MyCustomDateSerializer extends JsonSerializer<Date> {
    
        @Override
        public void serialize(final Date date, final JsonGeneraror generator,
              final SerializerProvider provider) throws IOException,
              JSONProcessingException {
    
            generator.writeString(yourRepresentationHere);
        }
    }
    

    All of this information is available in the Jackson Documentation, with the bulk of it in the section dealing with date handling.

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

Sidebar

Related Questions

I have folder structure and I would like to create JSON objects based on
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
I have structure like this class Lesson { List<Sign> signs { get; set; }
I have a hierarchical structure of objects (lets say, 3 levels). Class A is
I want to compare C++ class/structure objects. In C, most of the time, one
I have the next structure of DTO objects: public class MainDTO implements Serializable {
In Lua, I have a tree relationship structure between objects where an object can
I have objects in a tree structure, I would like to aggregate status information
I have a nested Python data structure with datetime.datetime objects and namedtuples along the
I have to transfer objects between activities. Objects are with complex structure. I'm not

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.