Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the issue where the toString of OffsetDateTime truncates trailing 0's #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/com/sforce/ws/bind/TypeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.math.BigDecimal;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQueries;
import java.util.*;
Expand All @@ -66,6 +67,8 @@ public class TypeMapper {
private static final HashSet<String> keywords = getKeyWords();
private static HashMap<String, Class<?>> primitiveClassCache = getPrimitiveClassCache();

private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
Copy link
Contributor

@mgrumbach mgrumbach Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the final X correct? If the OffsetDateTime value always has zero offset, then this should work. However, if non-zero offsets are possible, then we probably want XXX to match Salesforce. Note that OffsetDateTime.toString() uses XXXXX.

Copy link
Author

@rcunn87 rcunn87 Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I was encountering was that OffsetDataTime.toString uses the shortest of what whats listed in the javadoc, and then salesforce was rejecting the data.
Let me change it and give it a test


// True if interfaces are generated for the WSDL
private boolean generateInterfaces;
private boolean generateExtendedErrorCodes;
Expand Down Expand Up @@ -421,7 +424,7 @@ private void writeSingleObject(XmlOutputStream out, TypeInfo info, Object value)
String s = calendarCodec.getValueAsString(value);
writeSimpleType(out, info, s, true, Calendar.class.getName());
} else if (value instanceof OffsetDateTime) {
writeSimpleType(out, info, value.toString(), true, OffsetDateTime.class.getName());
writeSimpleType(out, info, DTF.format((OffsetDateTime)value), true, OffsetDateTime.class.getName());
} else if (value instanceof OffsetDate) {
writeSimpleType(out, info, value.toString(), true, OffsetDate.class.getName());
} else if (value instanceof OffsetTime) {
Expand All @@ -445,7 +448,6 @@ private void writeSingleObject(XmlOutputStream out, TypeInfo info, Object value)
writeString(out, info, value.toString(), true);
}
}

private void writeNull(XmlOutputStream out, TypeInfo info) throws IOException {
out.writeStartTag(getNamespace(info), info.getName());
out.writeAttribute(Constants.SCHEMA_INSTANCE_NS, "nil", "true");
Expand Down