From 3fa347155ac1946a2cb22b563c1d177fd25b8f04 Mon Sep 17 00:00:00 2001 From: Ryan Cunningham Date: Thu, 21 Apr 2022 10:16:22 -0500 Subject: [PATCH] Fixes the issue where the toString of OffsetDateTime truncates trailing Zeros --- src/main/java/com/sforce/ws/bind/TypeMapper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sforce/ws/bind/TypeMapper.java b/src/main/java/com/sforce/ws/bind/TypeMapper.java index 76df672b..2e708a18 100644 --- a/src/main/java/com/sforce/ws/bind/TypeMapper.java +++ b/src/main/java/com/sforce/ws/bind/TypeMapper.java @@ -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.*; @@ -66,6 +67,8 @@ public class TypeMapper { private static final HashSet keywords = getKeyWords(); private static HashMap> primitiveClassCache = getPrimitiveClassCache(); + private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + // True if interfaces are generated for the WSDL private boolean generateInterfaces; private boolean generateExtendedErrorCodes; @@ -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) { @@ -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");