Skip to content

Commit

Permalink
Merge pull request #258 from fancywriter/java-time-non-working
Browse files Browse the repository at this point in the history
fix non-working java-time feature #235 and update test
  • Loading branch information
reubencornel authored Jun 16, 2020
2 parents 1f89970 + 886b480 commit 1c6d1a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/sforce/ws/bind/TypeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@
public class TypeMapper {
public static final String HTML = "html";
private static HashMap<QName, String> nillableJavaMapping = getNillableXmlJavaMapping();
private final HashMap<QName, String> xmlJavaMapping = getXmlJavaMapping();
private final HashMap<String, QName> javaXmlMapping = getJavaXmlMapping();
private static final HashSet<String> keywords = getKeyWords();
private static HashMap<String, Class<?>> primitiveClassCache = getPrimitiveClassCache();

// True if interfaces are generated for the WSDL
private boolean generateInterfaces;
private boolean generateExtendedErrorCodes;

private HashMap<String, QName> getJavaXmlMapping() {
private Map<String, QName> getJavaXmlMapping(boolean javaTime) {
HashMap<String, QName> map = new HashMap<String, QName>();
map.put(String.class.getName(), new QName(Constants.SCHEMA_NS, "string"));
map.put(int.class.getName(), new QName(Constants.SCHEMA_NS, "int"));
Expand Down Expand Up @@ -101,7 +99,7 @@ private HashMap<String, QName> getJavaXmlMapping() {
return map;
}

private HashMap<QName, String> getXmlJavaMapping() {
private Map<QName, String> getXmlJavaMapping(boolean javaTime) {
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());
Expand Down Expand Up @@ -151,18 +149,20 @@ private static HashMap<String, Class<?>> getPrimitiveClassCache() {
return map;
}

private final boolean javaTime;
private String packagePrefix;
private String interfacePackagePrefix;
private final Map<QName, String> xmlJavaMapping;
private final Map<String, QName> javaXmlMapping;

public TypeMapper() {
this.javaTime = false;
this(null, null, false);
}

public TypeMapper(String packagePrefix, String interfacePackagePrefix, boolean javaTime) {
this.packagePrefix = packagePrefix;
this.interfacePackagePrefix = interfacePackagePrefix;
this.javaTime = javaTime;
this.xmlJavaMapping = getXmlJavaMapping(javaTime);
this.javaXmlMapping = getJavaXmlMapping(javaTime);
}

private CalendarCodec calendarCodec = new CalendarCodec();
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/com/sforce/ws/bind/TypeMapperTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sforce.ws.wsdl.Constants;
import org.junit.Test;

import javax.xml.namespace.QName;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.time.*;
Expand Down Expand Up @@ -99,6 +100,9 @@ public void testDateRead() throws PullParserException, IOException, ConnectionEx
TypeInfo info = new TypeInfo("", "a", Constants.SCHEMA_NS, "date", 0, 1, true);
TypeMapper mapper = new TypeMapper(null, null, true);

String javaClassName = mapper.getJavaClassName(new QName(Constants.SCHEMA_NS, "date"), null, false);
assertEquals(OffsetDate.class.getName(), javaClassName);

OffsetDate result1 = (OffsetDate) mapper.readObject(xmlWithoutTimeZone, info, OffsetDate.class);
assertEquals(ZoneOffset.UTC, result1.getOffset());
assertEquals(LocalDate.of(2019, 12, 2), result1.getDate());
Expand All @@ -121,9 +125,12 @@ public void testDateTimeRead() throws PullParserException, IOException, Connecti
xmlWithTimeZone.setInput(new ByteArrayInputStream(withTimeZone.getBytes()), "UTF-8");
xmlWithTimeZone.nextTag();

TypeInfo info = new TypeInfo("", "a", Constants.SCHEMA_NS, "datetime", 0, 1, true);
TypeInfo info = new TypeInfo("", "a", Constants.SCHEMA_NS, "dateTime", 0, 1, true);
TypeMapper mapper = new TypeMapper(null, null, true);

String javaClassName = mapper.getJavaClassName(new QName(Constants.SCHEMA_NS, "dateTime"), null, false);
assertEquals(OffsetDateTime.class.getName(), javaClassName);

OffsetDateTime result1 = (OffsetDateTime) mapper.readObject(xmlWithoutTimeZone, info, OffsetDateTime.class);
assertEquals(ZoneOffset.UTC, result1.getOffset());
assertEquals(LocalDateTime.of(2019, 12, 2, 11, 22, 33, 444000000), result1.toLocalDateTime());
Expand All @@ -149,6 +156,9 @@ public void testTimeRead() throws PullParserException, IOException, ConnectionEx
TypeInfo info = new TypeInfo("", "a", Constants.SCHEMA_NS, "time", 0, 1, true);
TypeMapper mapper = new TypeMapper(null, null, true);

String javaClassName = mapper.getJavaClassName(new QName(Constants.SCHEMA_NS, "time"), null, false);
assertEquals(OffsetTime.class.getName(), javaClassName);

OffsetTime result1 = (OffsetTime) mapper.readObject(xmlWithoutTimeZone, info, OffsetTime.class);
assertEquals(ZoneOffset.UTC, result1.getOffset());
assertEquals(LocalTime.of(11, 22, 33, 444000000), result1.toLocalTime());
Expand Down

0 comments on commit 1c6d1a4

Please sign in to comment.