0

I'm running into problems getting a Date (java.util.Date) object back from a ksoap2 response. Here is the response XML:

  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header></s:Header>
    <s:Body>
      <UpdateLocationResponse xmlns="http://tempuri.org/">
        <UpdateLocationResult>2012-05-07T13:34:34.7693883-04:00</UpdateLocationResult>
      </UpdateLocationResponse>
    </s:Body>
  </s:Envelope>

Here is the code I'm using to initialize the envelope and the request (** are used instead of real names due to security reasons):

static final String NAMESPACE = "http://tempuri.org/";
static final String URL = "http://****************.svc";

envelope.addMapping(NAMESPACE, "UpdateLocationResult", Date.class,
        new MarshalDate());
MarshalDate mdate = new MarshalDate();
mdate.register(envelope);
envelope.implicitTypes = true;

HttpTransportSE trans = new HttpTransportSE(URL);
trans.debug = true;

trans.call(SOAP_ACTION, envelope);
Object r = envelope.getResponse(); // r is always SoapPrimitive!!!
                                   // I want it to be a java.util.Date

I've tried all the combinations of namespaces, property names, and marshallers, to no avail. I always get a SoapPrimitive back from envelope.getResponse()

What am I doing wrong?

Aviad P.
  • 32,036
  • 14
  • 103
  • 124

1 Answers1

0

Isn't it also a String? Try using SimpleDateFormat

And this may be useful for you:

SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String strDate = response.toString();
Oguz Ozkeroglu
  • 3,025
  • 3
  • 38
  • 64
  • I can convert the `SoapPrimitive` to `String` and parse it for a `Date` myself of course, but I want the library to do it for me, by way of mapping... – Aviad P. May 08 '12 at 12:48