2

I used WSC-23.jar to convert enterprise WSDL file into a JAR. While the WSDL file had the Date fields/elements correctly marked with the type="xsd:date", generated Java classes for the SF objects have Date AND Datetime fields both of type Calendar.

Please advise what I need to do to generate correct Java classes.

Update: i thought that maybe i missed that java.util.date was deprecated in java 7, but it's not.

Update 2: Keith, thanks. Found the class where this mapping is set, and will modify it to be a Date not a Calendar: TypeMapper.java

private static HashMap<QName, String> getXmlJavaMapping() {
    HashMap<QName, String> map = new HashMap<QName, String>();
    map.put(new QName(Constants.SCHEMA_NS, "string"), String.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "int"), int.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "long"), long.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "float"), float.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "boolean"), boolean.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "date"), Calendar.class.getName());   // HERE IT IS
    map.put(new QName(Constants.SCHEMA_NS, "dateTime"), Calendar.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "time"), Time.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "base64Binary"), "byte[]");
    map.put(new QName(Constants.SCHEMA_NS, "double"), double.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "decimal"), double.class.getName());
    map.put(new QName(Constants.SCHEMA_NS, "anyType"), Object.class.getName());
    for (SfdcApiType type : SfdcApiType.values()) {
        map.put(new QName(type.getNamespace(), "ID"), String.class.getName());
        map.put(new QName(type.getNamespace(), "QueryLocator"), String.class.getName());
    }
    return map;
}
3

From a brief look at the WSC source code such as https://github.com/forcedotcom/wsc/blob/91fcfd97e7e87d2f0d64a32492b0592469c079a6/src/main/java/com/sforce/ws/bind/DateCodec.java the use of Calendar appears to be a fixed design decision in WSC.

When I have used WSC I've just used Java's Calendar interface methods such as getTime() that returns a Date and code like this to set a Date:

Calendar c = Calendar.getInstance();
c.clear();
c.setTime(d);
sob.setField(c);

and lived with it.

  • Great call, I should have looked in the source code for wsc. Found where it sets it - class name is TypeMapper.java – Kirill Yunussov Feb 20 '14 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.