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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:42:35+00:00 2026-05-15T15:42:35+00:00

I cannot get JAXB to unmarshal a timestamp in a Resteasy JAX-RS server application.

  • 0

I cannot get JAXB to unmarshal a timestamp in a Resteasy JAX-RS server application.

My class looks like this:

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "foo")
public final class Foo {
    // Other fields omitted

    @XmlElement(name = "timestamp", required = true)
    protected Date timestamp;

    public Foo() {}

    public Date getTimestamp() {
        return timestamp;
    }

    public String getTimestampAsString() {
        return (timestamp != null) ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp) : null;
    }

    public void setTimestamp(final Date timestamp) {
        this.timestamp = timestamp;
    }

    public void setTimestamp(final String timestampAsString) {
        try {
            this.timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timestampAsString);
        } catch (ParseException ex) {
            this.timestamp = null;
        }
    }
}

Any ideas?

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-05-15T15:42:36+00:00Added an answer on May 15, 2026 at 3:42 pm

    JAXB can handle the java.util.Date class. However it expects the format:

    “yyyy-MM-dd’T’HH:mm:ss” instead of “yyyy-MM-dd HH:mm:ss”

    If you want to use that date format I would suggest using an XmlAdapter, it would look something like the following:

    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import javax.xml.bind.annotation.adapters.XmlAdapter;
    
    public class DateAdapter extends XmlAdapter<String, Date> {
    
        private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
        @Override
        public String marshal(Date v) throws Exception {
            return dateFormat.format(v);
        }
    
        @Override
        public Date unmarshal(String v) throws Exception {
            return dateFormat.parse(v);
        }
    
    }
    

    You would then specify this adapter on your timestamp property:

    import java.util.Date;
    
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
    
    @XmlAccessorType(XmlAccessType.NONE) 
    @XmlRootElement(name = "foo") 
    public final class Foo { 
        // Other fields omitted 
    
        @XmlElement(name = "timestamp", required = true) 
        @XmlJavaTypeAdapter(DateAdapter.class)
        protected Date timestamp; 
    
        public Foo() {} 
    
        public Date getTimestamp() { 
            return timestamp; 
        } 
    
        public void setTimestamp(final Date timestamp) { 
            this.timestamp = timestamp; 
        } 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this warning from GCC: warning: cannot pass objects of non-POD type 'class
I get this message: Cannot find the X.509 certificate using the following search criteria:
I continue to get this error: Object '%s' cannot be renamed because the object
How can I get jaxb to bind to my Vector? I cannot seem to
I cannot get this crazy dependency to work and please don't tell me to
I cannot get this to work so I thought it might be a wise
The following code I cannot get to work (Jquery 1.4.2) It seems like the
Cannot get this to work. First time using variables passed into functions. Unchecking radio
I cannot get this to work: function formvalidation() { var SiteNum= document.getElementsByName(sitesinput)[0].value; var i=1;
I cannot get this (http://plugins.jquery.com/project/autogrowtextarea) jquery plugin to work. below is my code. I

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.