[ 
https://issues.apache.org/jira/browse/CAMEL-12334?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16409667#comment-16409667
 ] 

ASF GitHub Bot commented on CAMEL-12334:
----------------------------------------

zregvart closed pull request #2254: CAMEL-12334: Mapped date to LocalDate and 
time to LocalTime
URL: https://github.com/apache/camel/pull/2254
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/components/camel-salesforce/camel-salesforce-component/README.md 
b/components/camel-salesforce/camel-salesforce-component/README.md
index b923dfa0d94..00c65cc9368 100644
--- a/components/camel-salesforce/camel-salesforce-component/README.md
+++ b/components/camel-salesforce/camel-salesforce-component/README.md
@@ -1,7 +1,7 @@
 # Camel Salesforce component #
 
 This component supports producer and consumer endpoints to communicate with 
Salesforce using Java DTOs. 
-There is a companion maven plugin 
[camel-salesforce-plugin](https://github.com/dhirajsb/camel-salesforce-maven-plugin)
 that generates these DTOs. 
+There is a companion maven plugin 
[camel-salesforce-plugin](https://github.com/apache/camel/tree/master/components/camel-salesforce/camel-salesforce-maven-plugin)
 that generates these DTOs. 
 
 The component supports the following Salesforce APIs
 
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
 
b/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
index 5926d6fc17b..1cbb4e821a0 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/docs/salesforce-component.adoc
@@ -22,7 +22,7 @@ for this component:
 ----
 
 NOTE: Developers wishing to contribute to the component are instructed
-to look at the README.md file on instructions on how to get started and
+to look at the 
https://github.com/apache/camel/tree/master/components/camel-salesforce/camel-salesforce-component/README.md[README.md]
 file on instructions on how to get started and
 setup your environment for running integration tests.
 
 === Authenticating to Salesforce
@@ -535,8 +535,7 @@ final SObjectCompositeResult contactCreationResult = 
results.stream().filter(r -
 
 === Camel Salesforce Maven Plugin
 
-This Maven plugin generates DTOs for the Camel
-<<salesforce-component,Salesforce>>.
+This Maven plugin generates DTOs for the Camel. Please refer to 
https://github.com/apache/camel/tree/master/components/camel-salesforce/camel-salesforce-maven-plugin[README.md]
 for details on how to generated the DTO.
 
 === Options
 
@@ -666,29 +665,4 @@ with the following path and query parameters:
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer 
creates an exchange. |  | ExchangePattern
 | *synchronous* (advanced) | Sets whether synchronous processing should be 
strictly used, or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
 |===
-// endpoint options: END
-
-
-
-
-For obvious security reasons it is recommended that the clientId,
-clientSecret, userName and password fields be not set in the pom.xml.  
-The plugin should be configured for the rest of the properties, and can
-be executed using the following command:
-
-[source,java]
-----
-mvn camel-salesforce:generate -DcamelSalesforce.clientId=<clientid> 
-DcamelSalesforce.clientSecret=<clientsecret> \
-    -DcamelSalesforce.userName=<username> -DcamelSalesforce.password=<password>
-----
-
-The generated DTOs use Jackson and XStream annotations. All Salesforce
-field types are supported. Date and time fields are mapped to Joda
-DateTime, and picklist fields are mapped to generated Java Enumerations.
-
-=== See Also
-
-* Configuring Camel
-* Component
-* Endpoint
-* Getting Started
+// endpoint options: END
\ No newline at end of file
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateConverter.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateConverter.java
new file mode 100644
index 00000000000..6fa5ede14bd
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateConverter.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+import java.time.LocalDate;
+
+import com.thoughtworks.xstream.converters.ConversionException;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+/**
+ * XStream converter for handling {@link LocalDate} fields.
+ */
+public class DateConverter implements Converter {
+
+    @Override
+    public void marshal(Object o, HierarchicalStreamWriter writer, 
MarshallingContext context) {
+        LocalDate date = (LocalDate) o;
+        writer.setValue(DateTimeUtils.formatDate(date));
+    }
+
+    @Override
+    public Object unmarshal(HierarchicalStreamReader reader, 
UnmarshallingContext context) {
+        try {
+            return DateTimeUtils.parseDate(reader.getValue());
+        } catch (Exception e) {
+            throw new ConversionException(
+                    String.format("Error reading LocalDate from value %s: %s",
+                        reader.getValue(), e.getMessage()),
+                    e);
+        }
+    }
+
+    @Override
+    public boolean canConvert(Class aClass) {
+        return LocalDate.class.isAssignableFrom(aClass);
+    }
+
+}
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateDeserializer.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateDeserializer.java
new file mode 100644
index 00000000000..e39a695cbe1
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateDeserializer.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+import java.io.IOException;
+import java.time.LocalDate;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+
+public class DateDeserializer extends JsonDeserializer<LocalDate> {
+
+    public DateDeserializer() {
+        super();
+    }
+
+    @Override
+    public LocalDate deserialize(JsonParser jsonParser, DeserializationContext 
deserializationContext) throws IOException {
+        JsonToken currentToken = jsonParser.getCurrentToken();
+        if (currentToken == JsonToken.VALUE_STRING) {
+            return DateTimeUtils.parseDate(jsonParser.getText().trim());
+        }
+        throw JsonMappingException.from(deserializationContext, "Expected 
String value, got: " + currentToken);
+    }
+
+    @Override
+    public Class<?> handledType() {
+        return LocalDate.class;
+    }
+}
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateModule.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateModule.java
new file mode 100644
index 00000000000..7a2d5ade23b
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateModule.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+
+import java.time.LocalDate;
+
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+public class DateModule extends SimpleModule {
+
+    public DateModule() {
+        super();
+        addSerializer(LocalDate.class, new DateSerializer());
+        addDeserializer(LocalDate.class, new DateDeserializer());
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateSerializer.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateSerializer.java
new file mode 100644
index 00000000000..4f21d6e10db
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateSerializer.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+import java.io.IOException;
+import java.time.LocalDate;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import 
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
+
+
+public class DateSerializer extends JsonSerializer<LocalDate> {
+
+    public DateSerializer() {
+        super();
+    }
+
+    @Override
+    public void serialize(LocalDate date, JsonGenerator jsonGenerator, 
SerializerProvider serializerProvider) throws IOException {
+        jsonGenerator.writeString(DateTimeUtils.formatDate(date));
+    }
+
+    @Override
+    public Class<LocalDate> handledType() {
+        return LocalDate.class;
+    }
+
+    @Override
+    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, 
JavaType type) throws JsonMappingException {
+        visitor.expectStringFormat(type);
+    }
+}
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtils.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtils.java
index 0da515e357e..881da399f0e 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtils.java
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtils.java
@@ -17,12 +17,19 @@
 package org.apache.camel.component.salesforce.api.utils;
 
 import java.time.DateTimeException;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.DateTimeParseException;
 import java.util.regex.Pattern;
 
+import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
+import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
+
 /**
  * Utility class for working with DateTime fields.
  */
@@ -53,4 +60,23 @@ private static String normalizeDateTime(String 
dateTimeAsString) {
         }
         return dateTimeAsString;
     }
+    
+    public static String formatDate(LocalDate date) {
+        return ISO_LOCAL_DATE.format(date);
+    }
+    
+    public static LocalDate parseDate(String date) {
+        return ISO_LOCAL_DATE.parse(date,LocalDate::from);
+    }
+        
+    public static String formatTime(OffsetTime time) {
+        // Sets the timezone as UTC for the time before sending to salesforce
+        return 
ISO_LOCAL_TIME.format(time.withOffsetSameInstant(ZoneOffset.UTC).toLocalTime());
+    }
+    
+    public static OffsetTime parseTime(String time) {
+        // Sets the timezone as UTC for the time which comes from salesforce
+        return OffsetTime.of(ISO_LOCAL_TIME.parse(time, LocalTime::from), 
ZoneOffset.UTC);
+    }
+ 
 }
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/JsonUtils.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/JsonUtils.java
index d3619daa5d4..4fbe8765ff9 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/JsonUtils.java
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/JsonUtils.java
@@ -76,7 +76,9 @@ public static ObjectMapper createObjectMapper() {
         // enable date time support including Java 1.8 ZonedDateTime
         ObjectMapper objectMapper = new ObjectMapper();
         objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, 
false);
+        objectMapper.registerModule(new DateModule());
         objectMapper.registerModule(new DateTimeModule());
+        objectMapper.registerModule(new TimeModule());
         return objectMapper;
     }
 
@@ -190,13 +192,19 @@ public static JsonSchema 
getSObjectJsonSchemaAsSchema(SObjectDescription descrip
                 fieldSchema = new BooleanSchema();
                 break;
 
-            case "dateTime":
-            case "time":
             case "date":
+                fieldSchema = new StringSchema();
+                ((StringSchema) fieldSchema).setFormat(JsonValueFormat.DATE);
+                break;
+            case "dateTime": 
             case "g":
                 fieldSchema = new StringSchema();
                 ((StringSchema) 
fieldSchema).setFormat(JsonValueFormat.DATE_TIME);
                 break;
+            case "time":
+                fieldSchema = new StringSchema();
+                ((StringSchema) fieldSchema).setFormat(JsonValueFormat.TIME);
+                break;
 
             case "address":
                 if (addressSchema == null) {
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeConverter.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeConverter.java
new file mode 100644
index 00000000000..4f87b59f720
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeConverter.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+import java.time.OffsetTime;
+
+import com.thoughtworks.xstream.converters.ConversionException;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+/**
+ * XStream converter for handling {@link OffsetTime} fields.
+ */
+public class TimeConverter implements Converter {
+
+    @Override
+    public void marshal(Object o, HierarchicalStreamWriter writer, 
MarshallingContext context) {
+        OffsetTime time = (OffsetTime) o;
+        writer.setValue(DateTimeUtils.formatTime(time));
+    }
+
+    @Override
+    public Object unmarshal(HierarchicalStreamReader reader, 
UnmarshallingContext context) {
+        try {
+            return DateTimeUtils.parseTime(reader.getValue());
+        } catch (Exception e) {
+            throw new ConversionException(
+                    String.format("Error reading OffsetTime from value %s: %s",
+                        reader.getValue(), e.getMessage()),
+                    e);
+        }
+    }
+
+    @Override
+    public boolean canConvert(Class aClass) {
+        return OffsetTime.class.isAssignableFrom(aClass);
+    }
+
+}
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeDeserializer.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeDeserializer.java
new file mode 100644
index 00000000000..7363db4b539
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeDeserializer.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+import java.io.IOException;
+import java.time.OffsetTime;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+
+public class TimeDeserializer extends JsonDeserializer<OffsetTime> {
+
+    public TimeDeserializer() {
+        super();
+    }
+
+    @Override
+    public OffsetTime deserialize(JsonParser jsonParser, 
DeserializationContext deserializationContext) throws IOException {
+        JsonToken currentToken = jsonParser.getCurrentToken();
+        if (currentToken == JsonToken.VALUE_STRING) {
+            return DateTimeUtils.parseTime(jsonParser.getText().trim());
+        }
+        throw JsonMappingException.from(deserializationContext, "Expected 
String value, got: " + currentToken);
+    }
+
+    @Override
+    public Class<?> handledType() {
+        return OffsetTime.class;
+    }
+}
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java
new file mode 100644
index 00000000000..3cfea55ac92
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+
+import java.time.OffsetTime;
+
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+public class TimeModule extends SimpleModule {
+
+    public TimeModule() {
+        super();
+        addSerializer(OffsetTime.class, new TimeSerializer());
+        addDeserializer(OffsetTime.class, new TimeDeserializer());
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeSerializer.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeSerializer.java
new file mode 100644
index 00000000000..f8d684a9125
--- /dev/null
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeSerializer.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.utils;
+
+import java.io.IOException;
+import java.time.OffsetTime;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import 
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
+
+
+public class TimeSerializer extends JsonSerializer<OffsetTime> {
+
+    public TimeSerializer() {
+        super();
+    }
+
+    @Override
+    public void serialize(OffsetTime time, JsonGenerator jsonGenerator, 
SerializerProvider serializerProvider) throws IOException {
+        jsonGenerator.writeString(DateTimeUtils.formatTime(time));
+    }
+
+    @Override
+    public Class<OffsetTime> handledType() {
+        return OffsetTime.class;
+    }
+
+    @Override
+    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, 
JavaType type) throws JsonMappingException {
+        visitor.expectStringFormat(type);
+    }
+}
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultCompositeApiClient.java
 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultCompositeApiClient.java
index 9efc74bf439..bc682d3dcb6 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultCompositeApiClient.java
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultCompositeApiClient.java
@@ -52,7 +52,9 @@
 import 
org.apache.camel.component.salesforce.api.dto.composite.SObjectCompositeResponse;
 import org.apache.camel.component.salesforce.api.dto.composite.SObjectTree;
 import 
org.apache.camel.component.salesforce.api.dto.composite.SObjectTreeResponse;
+import org.apache.camel.component.salesforce.api.utils.DateConverter;
 import org.apache.camel.component.salesforce.api.utils.DateTimeConverter;
+import org.apache.camel.component.salesforce.api.utils.TimeConverter;
 import org.apache.camel.component.salesforce.api.utils.JsonUtils;
 import org.apache.camel.component.salesforce.api.utils.Version;
 import org.apache.camel.component.salesforce.internal.PayloadFormat;
@@ -307,7 +309,9 @@ public HierarchicalStreamWriter createWriter(final Writer 
out) {
         xStream.aliasSystemAttribute(null, "class");
         xStream.ignoreUnknownElements();
         XStreamUtils.addDefaultPermissions(xStream);
+        xStream.registerConverter(new DateConverter());
         xStream.registerConverter(new DateTimeConverter());
+        xStream.registerConverter(new TimeConverter());
         xStream.setMarshallingStrategy(new TreeMarshallingStrategy());
         xStream.processAnnotations(additionalTypes);
 
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtilsTest.java
 
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtilsTest.java
index a08f73bf571..f2bb8fe42e1 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtilsTest.java
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/DateTimeUtilsTest.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.component.salesforce.api.utils;
 
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.OffsetTime;
 import java.time.ZoneId;
+import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 
 import org.junit.Test;
@@ -44,4 +48,33 @@ public void testParseDateTime() {
         assertEquals(ZonedDateTime.of(1700, 1, 1, 1, 13, 14, 7000000, 
ZoneId.of("+00:19")), 
DateTimeUtils.parseDateTime("1700-01-01T01:13:14.007+00:19"));
         assertEquals(ZonedDateTime.of(1700, 2, 3, 2, 13, 14, 7000000, 
ZoneId.of("Z")), DateTimeUtils.parseDateTime("1700-02-03T02:13:14.007Z"));
     }
+
+    @Test
+    public void testFormatDate() {
+        assertEquals("1991-12-10", DateTimeUtils.formatDate(LocalDate.of(1991, 
12, 10)));
+        assertEquals("2100-12-10", DateTimeUtils.formatDate(LocalDate.of(2100, 
12, 10)));
+        assertEquals("1700-01-01", DateTimeUtils.formatDate(LocalDate.of(1700, 
 1,  1)));
+        }
+
+    @Test
+    public void testParseDate() {
+        assertEquals(LocalDate.of(1700, 01, 01), 
DateTimeUtils.parseDate("1700-01-01"));
+        assertEquals(LocalDate.of(2100, 12, 10), 
DateTimeUtils.parseDate("2100-12-10"));
+        assertEquals(LocalDate.of(1700,  1,  1), 
DateTimeUtils.parseDate("1700-01-01"));
+    }
+
+    @Test
+    public void testFormatTime() {
+        assertEquals("12:13:14.007", 
DateTimeUtils.formatTime(OffsetTime.of(12, 13, 14, 7000000,ZoneOffset.UTC)));
+        assertEquals("01:00:00", DateTimeUtils.formatTime(OffsetTime.of(1, 0, 
0, 0,ZoneOffset.UTC)));
+        assertEquals("00:00:00", 
DateTimeUtils.formatTime(OffsetTime.of(LocalTime.MIDNIGHT,ZoneOffset.UTC)));
+    }
+
+    @Test
+    public void testParseTime() {
+        assertEquals(OffsetTime.of(LocalTime.MIDNIGHT, ZoneOffset.UTC), 
DateTimeUtils.parseTime("00:00:00.000"));
+        assertEquals(OffsetTime.of(1, 0, 0, 100, ZoneOffset.UTC), 
DateTimeUtils.parseTime("01:00:00.0000001"));
+        assertEquals(OffsetTime.of(12, 13, 14, 7000000, ZoneOffset.UTC), 
DateTimeUtils.parseTime("12:13:14.007"));
+        assertEquals(OffsetTime.of(12, 13, 0, 0, ZoneOffset.UTC), 
DateTimeUtils.parseTime("12:13"));
+    }
 }
diff --git 
a/components/camel-salesforce/camel-salesforce-maven-plugin/README.md 
b/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
index 54f42c48b35..795fc14f562 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
@@ -1,6 +1,6 @@
 # Maven plugin for camel-salesforce component #
 
-This plugin generates DTOs for the [Camel Salesforce 
Component](https://github.com/dhirajsb/camel-salesforce). 
+This plugin generates DTOs for the [Camel Salesforce 
Component](https://github.com/apache/camel/tree/master/components/camel-salesforce/camel-salesforce-component).
 
 
 ## Usage ##
 
@@ -18,6 +18,8 @@ The plugin configuration has the following properties.
 * includePattern - Java RegEx for SObject types to include
 * excludePattern - Java RegEx for SObject types to exclude
 * packageName - Java package name for generated DTOs, defaults to 
org.apache.camel.salesforce.dto.
+* useZonedTimeDateForDate - it will use LocalDate for Date if set to false. By 
default or if set to true ZonedTimeDate will be used for Date.
+* useZonedTimeDateForTime - it will use OffsetTime with timezone offset set to 
UTC for Time if set to false. By default or if set to true ZonedTimeDate will 
be used for Time.
 
 Additonal properties to provide proxy information, if behind a firewall.
 
@@ -89,4 +91,4 @@ The plugin should be configured for the rest of the 
properties, and can be execu
 
        mvn camel-salesforce:generate -DcamelSalesforce.clientId=<clientid> 
-DcamelSalesforce.clientSecret=<clientsecret> 
-DcamelSalesforce.userName=<username> -DcamelSalesforce.password=<password>
 
-The generated DTOs use Jackson and XStream annotations. All Salesforce field 
types are supported. Date and time fields are mapped to 
java.time.ZonedDateTime, and picklist fields are mapped to generated Java 
Enumerations.
+The generated DTOs use Jackson and XStream annotations. All Salesforce field 
types are supported. DateTime and Timestamp fields are mapped to 
java.time.ZonedDateTime, and picklist fields are mapped to generated Java 
Enumerations.
diff --git 
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
 
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
index 7d1c452211b..5a717e8fff1 100644
--- 
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
+++ 
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
@@ -116,8 +116,11 @@ public String getFieldType(final SObjectDescription 
description, final SObjectFi
                 return description.getName() + "_" + 
enumTypeName(field.getName()) + "[]";
             } else {
                 // map field to Java type
-                final String soapType = field.getSoapType();
-                final String type = 
LOOKUP_MAP.get(soapType.substring(soapType.indexOf(':') + 1));
+                final String soapType = field.getSoapType().split(":",2)[1];
+                final String type = (
+                        (soapType.equals("date")&&useZonedTimeDateForDate) ||
+                        (soapType.equals("time")&&useZonedTimeDateForTime) )
+                        ? "java.time.ZonedDateTime" : LOOKUP_MAP.get(soapType);
                 if (type == null) {
                     getLog().warn(String.format("Unsupported field type %s in 
field %s of object %s", soapType,
                         field.getName(), description.getName()));
@@ -316,6 +319,18 @@ public String variableName(final String given) {
     @Parameter(property = "camelSalesforce.useStringsForPicklists", 
defaultValue = "false")
     private Boolean useStringsForPicklists;
 
+    /**
+     * Generator will use java.time.ZonedTimeDate for Date if set to true, 
else it will default to java.time.LocalDate
+     */
+    @Parameter(property = "camelSalesforce.useZonedTimeDateForDate", 
defaultValue = "true")
+    private boolean useZonedTimeDateForDate;
+ 
+    /**
+     * Generator will use java.time.ZonedTimeDate for Time if set to true, 
else it will default to java.time.OffsetTime
+     */
+    @Parameter(property = "camelSalesforce.useZonedTimeDateForTime", 
defaultValue = "true")
+    private boolean useZonedTimeDateForTime;
+    
     void processDescription(final File pkgDir, final SObjectDescription 
description, final GeneratorUtility utility,
         final String generatedDate) throws IOException {
         // generate a source file for SObject
@@ -475,8 +490,8 @@ static VelocityEngine createVelocityEngine() {
             {"unsignedInt", "Long"}, //
             {"unsignedShort", "Integer"}, //
             {"unsignedByte", "Short"}, //
-            {"time", "java.time.ZonedDateTime"}, //
-            {"date", "java.time.ZonedDateTime"}, //
+            {"time", "java.time.OffsetTime"}, //
+            {"date", "java.time.LocalDate"}, //
             {"g", "java.time.ZonedDateTime"}, //
             // Salesforce maps any types like string, picklist, reference, etc.
             // to string


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Salesforce DTO does not use correct datatype for "date" and "time" field
> ------------------------------------------------------------------------
>
>                 Key: CAMEL-12334
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12334
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-salesforce
>    Affects Versions: 2.20.2
>            Reporter: Hemang Ajmera
>            Assignee: Zoran Regvart
>            Priority: Major
>              Labels: maven
>             Fix For: 2.22.0
>
>
> The DTO classes generated by the Maven plugin uses ZonedDateTime for all three
>  * datetime
>  * date
>  * time
> The generation works fine, but is is not able to marshal/unmarshal correctly.
> The DTO should use different kind of field. My suggestion is to use
>  * ZonedDateTime for datetime
>  * LocalDate for date
>  * LocalTime for time
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to