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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:28:59+00:00 2026-05-20T10:28:59+00:00

I have a simple web service method that returns a simple java class as

  • 0

I have a simple web service method that returns a simple java class as return value.

@WebMethod()
public SimpleClass myMethod();

@XmlRootElement()
public class SimpleClass {
    @XmlElement(name="myDate")
    @XmlJavaTypeAdapter(value=MyDateAdapter.class)
    public java.sql.Date myDate = new java.sql.Date(new java.util.Date().getTime());
}

I want that java.sql.Date will transmitted as Long value in the XML (because the client is J2ME that cannot handle complex things).
For this puprpose I took the solution that was mentioned in many places before, and worked great on Glassfish v2.

First, I declare the following adapter:

 public class MyDateAdapter extends XmlAdapter<Long, java.sql.Date> {
     public java.sql.Date unmarshal(Long v) throws Exception {
        return new java.sql.Date(v);
     }
     public Long marshal(java.sql.Date v) throws Exception {
         return v.getTime();
     }
 }

Then, I declare its usage in package-info file like this:

 @XmlJavaTypeAdapters({
    @XmlJavaTypeAdapter(value=MyDateAdapter.class,type=java.sql.Date.class)
 })
 package mingler.tracker.ejb.client;

The problem happens on GlassFish 3. The date is transmitted as “xs:dateTime” value, instead of Long, although I defined the adapter properly.
This is the response I get from GlassFish 3 server, when I call my web service:

<?xml version="1.0" encoding="UTF-8"?>
 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
     <S:Body>
         <ns2:myMethodResponse xmlns:ns2="http://nevermind.com">
             <return>
                 <myDate xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:dateTime">2010-12-09T12:44:06.875+02:00</myDate>
             </return>
         </ns2:myMethodResponse>
     </S:Body>
 </S:Envelope>

I also checked with the debugger — the functions in the adapter are never called.
On the other hand, the adapater is not useless, because if I try to remove it I get JAXB exception,
telling me that java.sql.Date cannot be handled because it doesn’t have no-arg constructor.

Any ideas?

20/12/2010 –
I added links to a project jar with sources and the results for glassfish2 and glassfish3:
jar file ,glassfish3 result , glassfish2 result

  • 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-20T10:29:00+00:00Added an answer on May 20, 2026 at 10:29 am

    I have posted a bug for this issue, it should be solved on version 3.1 (link)

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

Sidebar

Related Questions

I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
Pretty simple scenario. I have a web service that receives a byte array that
I have a simple web page that till now didn't need any login. It
I have a really simple ASP.NET web application and a web setup project that
I have a simple PowerShell script that uses WMI to create a web site
I have a web service on an insecure network that needs authorization. I wish
I have a simple ASP.NET 3.5 SP1 Web Forms app... I've added the System.Web.Routing
I am writing a simple database with web access. I have previous experience with
I have been scouring the web for a code sample that shows how to
I'm out to create a fairly simple web service for intranet use. The service

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.