Repository: camel
Updated Branches:
  refs/heads/master 8d66f16cd -> e37135fbc


ServiceNow: simplify the json-schema and allow to customize date/time format


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e37135fb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e37135fb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e37135fb

Branch: refs/heads/master
Commit: e37135fbc9f8b777d8001f6b136c651b695fe49e
Parents: 8d66f16
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Sun Aug 6 10:07:59 2017 +0200
Committer: lburgazzoli <lburgazz...@gmail.com>
Committed: Sun Aug 6 10:07:59 2017 +0200

----------------------------------------------------------------------
 .../camel-servicenow-component/pom.xml          | 10 +++
 .../src/main/docs/servicenow-component.adoc     |  5 +-
 .../servicenow/AbstractServiceNowProcessor.java |  2 +-
 .../component/servicenow/ServiceNowClient.java  |  2 +-
 .../servicenow/ServiceNowConfiguration.java     | 94 +++++++++++++++++---
 .../servicenow/ServiceNowConstants.java         |  4 +
 .../servicenow/ServiceNowMetaDataExtension.java | 51 ++++-------
 .../ServiceNowMetaDataExtensionTest.java        | 88 ++++++++++++++++--
 .../src/it/simple-it/verify.groovy              |  1 +
 .../maven/CamelServiceNowGenerateMojo.java      | 69 ++++++--------
 .../ServiceNowComponentConfiguration.java       | 36 ++++++++
 11 files changed, 265 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/camel-servicenow-component/pom.xml 
b/components/camel-servicenow/camel-servicenow-component/pom.xml
index ea7040d..c85131f 100644
--- a/components/camel-servicenow/camel-servicenow-component/pom.xml
+++ b/components/camel-servicenow/camel-servicenow-component/pom.xml
@@ -92,6 +92,16 @@
       <version>${jackson2-version}</version>
     </dependency>
     <dependency>
+      <groupId>com.fasterxml.jackson.datatype</groupId>
+      <artifactId>jackson-datatype-jsr310</artifactId>
+      <version>${jackson2-version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.datatype</groupId>
+      <artifactId>jackson-datatype-jdk8</artifactId>
+      <version>${jackson2-version}</version>
+    </dependency>
+    <dependency>
       <groupId>com.fasterxml.jackson.jaxrs</groupId>
       <artifactId>jackson-jaxrs-json-provider</artifactId>
       <version>${jackson2-version}</version>

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/main/docs/servicenow-component.adoc
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/docs/servicenow-component.adoc
 
b/components/camel-servicenow/camel-servicenow-component/src/main/docs/servicenow-component.adoc
index 197ebd9..2b0929d 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/docs/servicenow-component.adoc
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/docs/servicenow-component.adoc
@@ -66,7 +66,7 @@ with the following path and query parameters:
 | **instanceName** | *Required* The ServiceNow instance name |  | String
 |=======================================================================
 
-#### Query Parameters (41 parameters):
+#### Query Parameters (44 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |=======================================================================
@@ -96,11 +96,14 @@ with the following path and query parameters:
 | **target** (producer) | Set this parameter to true to return only scorecards 
that have a target. |  | Boolean
 | **topLevelOnly** (producer) | Gets only those categories whose parent is a 
catalog. |  | Boolean
 | **apiVersion** (advanced) | The ServiceNow REST API version default latest | 
 | String
+| **dateFormat** (advanced) | The date format used for Json 
serialization/deserialization | yyyy-MM-dd | String
+| **dateTimeFormat** (advanced) | The date-time format used for Json 
serialization/deserialization | yyyy-MM-dd HH:mm:ss | String
 | **httpClientPolicy** (advanced) | To configure http-client |  | 
HTTPClientPolicy
 | **mapper** (advanced) | Sets Jackson's ObjectMapper to use for request/reply 
|  | ObjectMapper
 | **proxyAuthorizationPolicy** (advanced) | To configure proxy authentication 
|  | ProxyAuthorization Policy
 | **retrieveTargetRecordOn Import** (advanced) | Set this parameter to true to 
retrieve the target record when using import set api. The import set result is 
then replaced by the target record | false | Boolean
 | **synchronous** (advanced) | Sets whether synchronous processing should be 
strictly used or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
+| **timeFormat** (advanced) | The time format used for Json 
serialization/deserialization | HH:mm:ss | String
 | **proxyHost** (proxy) | The proxy host name |  | String
 | **proxyPort** (proxy) | The proxy port number |  | Integer
 | **apiUrl** (security) | The ServiceNow REST API url |  | String

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java
index 1ae25af..366c532 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java
@@ -48,7 +48,7 @@ public abstract class AbstractServiceNowProcessor implements 
Processor {
         this.javaTypeCache = new JavaTypeCache();
         this.endpoint = endpoint;
         this.config = endpoint.getConfiguration();
-        this.mapper = ObjectHelper.notNull(config.getMapper(), "mapper");
+        this.mapper = config.getOrCreateMapper();
         this.client = new ServiceNowClient(endpoint.getCamelContext(), config);
         this.dispatchers = new ArrayList<>();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java
index 5128797..9fd7886 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java
@@ -52,7 +52,7 @@ public final class ServiceNowClient {
             configuration.getApiUrl(),
             Arrays.asList(
                 new AuthenticationRequestFilter(configuration),
-                new JacksonJsonProvider(configuration.getMapper())
+                new JacksonJsonProvider(configuration.getOrCreateMapper())
             ),
             true
         );

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
index bc46bcb..67d6390 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
@@ -16,13 +16,25 @@
  */
 package org.apache.camel.component.servicenow;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.Map;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
-
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
@@ -34,15 +46,6 @@ import 
org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 
 @UriParams
 public class ServiceNowConfiguration implements Cloneable {
-
-    private static final ObjectMapper MAPPER = new ObjectMapper()
-        .configure(
-            DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
-            false)
-        .setSerializationInclusion(
-            JsonInclude.Include.NON_NULL
-        );
-
     @UriParam(label = "security", secret = true)
     @Metadata(required = "true")
     private String userName;
@@ -108,7 +111,7 @@ public class ServiceNowConfiguration implements Cloneable {
     @UriParam(prefix = "response-model.", multiValue = true, javaType = 
"java.lang.String")
     private Map<String, Class<?>> responseModels;
     @UriParam(label = "advanced")
-    private ObjectMapper mapper = MAPPER;
+    private ObjectMapper mapper;
     @UriParam(defaultValue = "HELSINKI", enums = "FUJI,GENEVA,HELSINKI")
     private ServiceNowRelease release = ServiceNowRelease.HELSINKI;
     @UriParam(label = "security")
@@ -125,6 +128,12 @@ public class ServiceNowConfiguration implements Cloneable {
     private String proxyUserName;
     @UriParam(label = "proxy,security")
     private String proxyPassword;
+    @UriParam(label = "advanced", defaultValue = 
ServiceNowConstants.DEFAULT_DATE_FORMAT)
+    private String dateFormat = ServiceNowConstants.DEFAULT_DATE_FORMAT;
+    @UriParam(label = "advanced", defaultValue = 
ServiceNowConstants.DEFAULT_TIME_FORMAT)
+    private String timeFormat = ServiceNowConstants.DEFAULT_TIME_FORMAT;
+    @UriParam(label = "advanced", defaultValue = 
ServiceNowConstants.DEFAULT_DATE_TIME_FORMAT)
+    private String dateTimeFormat = 
ServiceNowConstants.DEFAULT_DATE_TIME_FORMAT;
 
     public String getUserName() {
         return userName;
@@ -480,6 +489,36 @@ public class ServiceNowConfiguration implements Cloneable {
         return mapper;
     }
 
+    public ObjectMapper getOrCreateMapper() {
+        if (mapper == null) {
+            final DateTimeFormatter dateFormat = 
DateTimeFormatter.ofPattern(getDateFormat());
+            final DateTimeFormatter timeFormat = 
DateTimeFormatter.ofPattern(getTimeFormat());
+            final DateTimeFormatter dateTimeFormat = 
DateTimeFormatter.ofPattern(getDateTimeFormat());
+
+            this.mapper = new ObjectMapper()
+                .registerModule(new Jdk8Module())
+                .registerModule(new JavaTimeModule()
+                    .addSerializer(LocalDate.class, new 
LocalDateSerializer(dateFormat))
+                    .addDeserializer(LocalDate.class, new 
LocalDateDeserializer(dateFormat))
+                    .addSerializer(LocalTime.class, new 
LocalTimeSerializer(timeFormat))
+                    .addDeserializer(LocalTime.class, new 
LocalTimeDeserializer(timeFormat))
+                    .addSerializer(LocalDateTime.class, new 
LocalDateTimeSerializer(dateTimeFormat))
+                    .addDeserializer(LocalDateTime.class, new 
LocalDateTimeDeserializer(dateTimeFormat))
+                )
+                .configure(
+                    SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
+                    false)
+                .configure(
+                    DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
+                    false)
+                .setSerializationInclusion(
+                    JsonInclude.Include.NON_NULL
+                );
+        }
+
+        return mapper;
+    }
+
     public boolean hasMapper() {
         return mapper != null;
     }
@@ -585,6 +624,39 @@ public class ServiceNowConfiguration implements Cloneable {
         this.proxyPassword = proxyPassword;
     }
 
+    public String getDateFormat() {
+        return dateFormat;
+    }
+
+    /**
+     * The date format used for Json serialization/deserialization
+     */
+    public void setDateFormat(String dateFormat) {
+        this.dateFormat = dateFormat;
+    }
+
+    public String getTimeFormat() {
+        return timeFormat;
+    }
+
+    /**
+     * The time format used for Json serialization/deserialization
+     */
+    public void setTimeFormat(String timeFormat) {
+        this.timeFormat = timeFormat;
+    }
+
+    public String getDateTimeFormat() {
+        return dateTimeFormat;
+    }
+
+    /**
+     * The date-time format used for Json serialization/deserialization
+     */
+    public void setDateTimeFormat(String dateTimeFormat) {
+        this.dateTimeFormat = dateTimeFormat;
+    }
+
     // *************************************************
     //
     // *************************************************

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
index b967bbe..e2272ec 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
@@ -37,6 +37,10 @@ public final class ServiceNowConstants {
     public static final String RESPONSE_TYPE = "CamelServiceNowResponseType";
     public static final String RETRIEVE_TARGET_RECORD = 
"CamelServiceNowRetrieveTargetRecord";
 
+    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
+    public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
+    public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd 
HH:mm:ss";
+
     public static final String ATTACHMENT_META_HEADER = 
"X-Attachment-Metadata";
 
     public static final String RESOURCE_TABLE = "table";

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
index b946438..d910d24 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
@@ -83,7 +83,7 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
     private Optional<MetaDataExtension.MetaData> tableMeta(MetaContext 
context) {
         try {
             final List<String> names = getObjectHierarchy(context);
-            final ObjectNode root = 
context.getConfiguration().getMapper().createObjectNode();
+            final ObjectNode root = 
context.getConfiguration().getOrCreateMapper().createObjectNode();
             final String baseUrn = 
(String)context.getParameters().getOrDefault("baseUrn", 
"org:apache:camel:component:servicenow");
 
             if (names.isEmpty()) {
@@ -99,10 +99,8 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
             // Schema sections
             root.putObject("properties");
             root.putArray("required");
-            root.putObject("definitions");
 
             loadProperties(context);
-            registerDefinitions(context, root);
 
             for (String name : names) {
                 context.getStack().push(name);
@@ -112,10 +110,16 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
                 context.getStack().pop();
             }
 
+            final String dateFormat = 
properties.getOrDefault("glide.sys.date_format", "yyyy-MM-dd");
+            final String timeFormat = 
properties.getOrDefault("glide.sys.time_format", "HH:mm:ss");
+
             return Optional.of(
                 MetaDataBuilder.on(getCamelContext())
                     .withAttribute(MetaData.CONTENT_TYPE, 
"application/schema+json")
                     .withAttribute(MetaData.JAVA_TYPE, JsonNode.class)
+                    .withAttribute("date.format", dateFormat)
+                    .withAttribute("time.format", timeFormat)
+                    .withAttribute("date-time.format", dateFormat + " " + 
timeFormat)
                     .withPayload(root)
                     .build()
             );
@@ -171,33 +175,6 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
     }
 
     // ********************************
-    // Definitions
-    // ********************************
-
-    private void registerDefinitions(MetaContext context, ObjectNode root) {
-        final ObjectNode definitions = (ObjectNode)root.get("definitions");
-
-        // Global Unique ID
-        definitions.putObject("guid")
-            .put("type", "string")
-            .put("pattern", "^[a-fA-F0-9]{32}");
-
-        // Date/Time
-        String dateFormat = properties.getOrDefault("glide.sys.date_format", 
"yyyy-MM-dd");
-        String timeFormat = properties.getOrDefault("glide.sys.time_format", 
"HH:mm:ss");
-
-        definitions.putObject("date")
-            .put("type", "string")
-            .put("format", dateFormat);
-        definitions.putObject("time")
-            .put("type", "string")
-            .put("format", timeFormat);
-        definitions.putObject("date-time")
-            .put("type", "string")
-            .put("format", dateFormat + " " + timeFormat);
-    }
-
-    // ********************************
     // Dictionary
     // ********************************
 
@@ -267,7 +244,7 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
                 LOGGER.debug("Load dictionary element <{}>", 
context.getStack());
 
                 try {
-                    final DictionaryEntry entry = 
context.getConfiguration().getMapper().treeToValue(node, DictionaryEntry.class);
+                    final DictionaryEntry entry = 
context.getConfiguration().getOrCreateMapper().treeToValue(node, 
DictionaryEntry.class);
                     final ObjectNode property = 
((ObjectNode)root.get("properties")).putObject(id);
 
                     // Add custom fields for code generation, json schema
@@ -289,19 +266,23 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
                         break;
                     case "guid":
                     case "GUID":
-                        property.put("$ref", "#/definitions/guid");
+                        property.put("type", "string");
+                        property.put("pattern", "^[a-fA-F0-9]{32}");
                         break;
                     case "glide_date":
-                        property.put("$ref", "#/definitions/date");
+                        property.put("type", "string");
+                        property.put("format", "date");
                         break;
                     case "due_date":
                     case "glide_date_time":
                     case "glide_time":
                     case "glide_duration":
-                        property.put("$ref", "#/definitions/date-time");
+                        property.put("type", "string");
+                        property.put("format", "date-time");
                         break;
                     case "reference":
-                        property.put("$ref", "#/definitions/guid");
+                        property.put("type", "string");
+                        property.put("pattern", "^[a-fA-F0-9]{32}");
 
                         if (entry.getReference().getValue() != null) {
                             // the referenced object type

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
 
b/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
index 1ddd0cb..bdf7049 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.component.servicenow;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.temporal.ChronoUnit;
 import java.util.Map;
 
 import com.fasterxml.jackson.databind.JsonNode;
@@ -63,12 +67,10 @@ public class ServiceNowMetaDataExtensionTest extends 
ServiceNowTestSupport {
         MetaDataExtension.MetaData result = 
getExtension().meta(parameters).orElseThrow(RuntimeException::new);
 
         Assert.assertEquals("application/schema+json", 
result.getAttribute(MetaDataExtension.MetaData.CONTENT_TYPE));
+        Assert.assertNotNull(result.getAttribute("date.format"));
+        Assert.assertNotNull(result.getAttribute("time.format"));
+        Assert.assertNotNull(result.getAttribute("date-time.format"));
         Assert.assertEquals(JsonNode.class, 
result.getAttribute(MetaDataExtension.MetaData.JAVA_TYPE));
-        
Assert.assertTrue(result.getPayload(JsonNode.class).hasNonNull("definitions"));
-        
Assert.assertTrue(result.getPayload(JsonNode.class).get("definitions").hasNonNull("guid"));
-        
Assert.assertTrue(result.getPayload(JsonNode.class).get("definitions").hasNonNull("date"));
-        
Assert.assertTrue(result.getPayload(JsonNode.class).get("definitions").hasNonNull("time"));
-        
Assert.assertTrue(result.getPayload(JsonNode.class).get("definitions").hasNonNull("date-time"));
         
Assert.assertTrue(result.getPayload(JsonNode.class).hasNonNull("properties"));
 
         LOGGER.debug(
@@ -84,4 +86,80 @@ public class ServiceNowMetaDataExtensionTest extends 
ServiceNowTestSupport {
 
         getExtension().meta(parameters);
     }
+
+    // *********************************
+    // Date/Time
+    // *********************************
+
+    @Test
+    public void testDateTimeWithDefaults() throws Exception {
+        final ServiceNowConfiguration configuration = new 
ServiceNowConfiguration();
+
+        ObjectMapper mapper = configuration.getOrCreateMapper();
+        DateTimeBean bean = new DateTimeBean();
+        String serialized = mapper.writeValueAsString(bean);
+
+        LOGGER.debug(serialized);
+
+        DateTimeBean deserialized = mapper.readValue(serialized, 
DateTimeBean.class);
+
+        Assert.assertEquals(bean.dateTime, deserialized.dateTime);
+        Assert.assertEquals(bean.date, deserialized.date);
+        Assert.assertEquals(bean.time, deserialized.time);
+    }
+
+    @Test
+    public void testDateTimeWithCustomFormats() throws Exception {
+        final ServiceNowConfiguration configuration = new 
ServiceNowConfiguration();
+        configuration.setDateFormat("yyyyMMdd");
+        configuration.setTimeFormat("HHmmss");
+
+        ObjectMapper mapper = configuration.getOrCreateMapper();
+        DateTimeBean bean = new DateTimeBean();
+        String serialized = mapper.writeValueAsString(bean);
+
+        LOGGER.debug(serialized);
+
+        DateTimeBean deserialized = mapper.readValue(serialized, 
DateTimeBean.class);
+
+        Assert.assertEquals(bean.dateTime, deserialized.dateTime);
+        Assert.assertEquals(bean.date, deserialized.date);
+        Assert.assertEquals(bean.time, deserialized.time);
+    }
+
+    public static class DateTimeBean {
+        LocalDateTime dateTime;
+        LocalDate date;
+        LocalTime time;
+
+        public DateTimeBean() {
+            dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);
+            date = dateTime.toLocalDate();
+            time = dateTime.toLocalTime();
+        }
+
+        public LocalDateTime getDateTime() {
+            return dateTime;
+        }
+
+        public void setDateTime(LocalDateTime dateTime) {
+            this.dateTime = dateTime;
+        }
+
+        public LocalDate getDate() {
+            return date;
+        }
+
+        public void setDate(LocalDate date) {
+            this.date = date;
+        }
+
+        public LocalTime getTime() {
+            return time;
+        }
+
+        public void setTime(LocalTime time) {
+            this.time = time;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-maven-plugin/src/it/simple-it/verify.groovy
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-maven-plugin/src/it/simple-it/verify.groovy
 
b/components/camel-servicenow/camel-servicenow-maven-plugin/src/it/simple-it/verify.groovy
index 91d565d..949edc5 100644
--- 
a/components/camel-servicenow/camel-servicenow-maven-plugin/src/it/simple-it/verify.groovy
+++ 
b/components/camel-servicenow/camel-servicenow-maven-plugin/src/it/simple-it/verify.groovy
@@ -19,3 +19,4 @@
 File sourceDir = new File(basedir, "target/generated-sources/camel-servicenow")
 
 assert sourceDir.isDirectory()
+assert sourceDir.listFiles().length == 1

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/components/camel-servicenow/camel-servicenow-maven-plugin/src/main/java/org/apache/camel/maven/CamelServiceNowGenerateMojo.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-maven-plugin/src/main/java/org/apache/camel/maven/CamelServiceNowGenerateMojo.java
 
b/components/camel-servicenow/camel-servicenow-maven-plugin/src/main/java/org/apache/camel/maven/CamelServiceNowGenerateMojo.java
index 58213ad..7ecb09f 100644
--- 
a/components/camel-servicenow/camel-servicenow-maven-plugin/src/main/java/org/apache/camel/maven/CamelServiceNowGenerateMojo.java
+++ 
b/components/camel-servicenow/camel-servicenow-maven-plugin/src/main/java/org/apache/camel/maven/CamelServiceNowGenerateMojo.java
@@ -18,8 +18,10 @@ package org.apache.camel.maven;
 
 import java.io.File;
 import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -29,13 +31,11 @@ import java.util.stream.Stream;
 import javax.annotation.Generated;
 import javax.lang.model.element.Modifier;
 
-import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.squareup.javapoet.AnnotationSpec;
 import com.squareup.javapoet.FieldSpec;
 import com.squareup.javapoet.JavaFile;
@@ -208,14 +208,13 @@ public class CamelServiceNowGenerateMojo extends 
AbstractMojo {
 
     private void generateBeanProperty(TypeSpec.Builder typeBuilder, JsonNode 
schema, String name, JsonNode definition) {
         final ArrayNode required = (ArrayNode)schema.get("required");
-        final ObjectNode definitions = (ObjectNode)schema.get("definitions");
         final String fieldName = toCamelCase(name, true);
         final String methodName = toCamelCase(name, false);
+        final JsonNode type = definition.get("type");
+        final JsonNode format = definition.get("format");
 
         Class<?> javaType = String.class;
-        Optional<String> format = Optional.empty();
 
-        JsonNode type = definition.get("type");
         if (type != null) {
             if ("boolean".equalsIgnoreCase(type.textValue())) {
                 javaType = boolean.class;
@@ -226,55 +225,47 @@ public class CamelServiceNowGenerateMojo extends 
AbstractMojo {
             if ("number".equalsIgnoreCase(type.textValue())) {
                 javaType = Double.class;
             }
-        }
-
-        JsonNode ref = definition.get("$ref");
-        if (ref != null) {
-            if ("#/definitions/guid".equalsIgnoreCase(ref.textValue())) {
+            if ("string".equalsIgnoreCase(type.textValue())) {
                 javaType = String.class;
             }
-            if ("#/definitions/date".equalsIgnoreCase(ref.textValue())) {
-                javaType = Date.class;
-                format = getNodeTextValue(definitions, "date", "format");
+        }
+
+        if (javaType == String.class && format != null) {
+            if ("date".equalsIgnoreCase(format.textValue())) {
+                javaType = LocalDate.class;
             }
-            if ("#/definitions/time".equalsIgnoreCase(ref.textValue())) {
-                javaType = Date.class;
-                format = getNodeTextValue(definitions, "time", "format");
+            if ("time".equalsIgnoreCase(format.textValue())) {
+                javaType = LocalTime.class;
             }
-            if ("#/definitions/date-time".equalsIgnoreCase(ref.textValue())) {
-                javaType = Date.class;
-                format = getNodeTextValue(definitions, "date-time", "format");
+            if ("date-time".equalsIgnoreCase(format.textValue())) {
+                javaType = LocalDateTime.class;
             }
         }
 
-        FieldSpec.Builder field = FieldSpec.builder(javaType, 
toCamelCase(name, true))
+        FieldSpec field = FieldSpec.builder(javaType, toCamelCase(name, true))
             .addModifiers(Modifier.PRIVATE)
             .addAnnotation(AnnotationSpec.builder(JsonProperty.class)
                 .addMember("value", "$S", name)
                 .addMember("required", "$L", required.has(name))
-                .build());
-
-        format.ifPresent(f ->
-            field.addAnnotation(AnnotationSpec.builder(JsonFormat.class)
-                .addMember("shape", "$L","JsonFormat.Shape.STRING")
-                .addMember("pattern", "$S", f)
                 .build())
-        );
+            .build();
 
-        MethodSpec.Builder getter = MethodSpec.methodBuilder("get" + 
methodName)
+        MethodSpec getter = MethodSpec.methodBuilder("get" + methodName)
             .addModifiers(Modifier.PUBLIC)
             .returns(javaType)
-            .addStatement("return this.$L", fieldName);
+            .addStatement("return this.$L", fieldName)
+            .build();
 
-        MethodSpec.Builder setter = MethodSpec.methodBuilder("set" + 
methodName)
+        MethodSpec setter = MethodSpec.methodBuilder("set" + methodName)
             .addModifiers(Modifier.PUBLIC)
             .returns(void.class)
             .addParameter(javaType, fieldName)
-            .addStatement("this.$L = $L", fieldName, fieldName);
+            .addStatement("this.$L = $L", fieldName, fieldName)
+            .build();
 
-        typeBuilder.addField(field.build());
-        typeBuilder.addMethod(getter.build());
-        typeBuilder.addMethod(setter.build());
+        typeBuilder.addField(field);
+        typeBuilder.addMethod(getter);
+        typeBuilder.addMethod(setter);
     }
 
     // ************************************
@@ -312,13 +303,5 @@ public class CamelServiceNowGenerateMojo extends 
AbstractMojo {
     private void validateSchema(JsonNode schema) throws MojoExecutionException 
{
         getNode(schema, "required")
             .orElseThrow(() -> new MojoExecutionException("Invalid JsonSchema: 
'required' element not found"));
-        getNode(schema, "definitions")
-            .orElseThrow(() -> new MojoExecutionException("Invalid JsonSchema: 
'definitions' element not found"));
-        getNode(schema, "definitions", "date", "format")
-            .orElseThrow(() -> new MojoExecutionException("Invalid JsonSchema: 
'#/definitions/date' element not found"));
-        getNode(schema, "definitions", "time", "format")
-            .orElseThrow(() -> new MojoExecutionException("Invalid JsonSchema: 
'#/definitions/time' element not found"));
-        getNode(schema, "definitions", "date-time", "format")
-            .orElseThrow(() -> new MojoExecutionException("Invalid JsonSchema: 
'#/definitions/date-time' element not found"));
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e37135fb/platforms/spring-boot/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java
index de23938..a9c8bf3 100644
--- 
a/platforms/spring-boot/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java
@@ -354,6 +354,18 @@ public class ServiceNowComponentConfiguration
          * Password for proxy authentication
          */
         private String proxyPassword;
+        /**
+         * The date format used for Json serialization/deserialization
+         */
+        private String dateFormat = "yyyy-MM-dd";
+        /**
+         * The time format used for Json serialization/deserialization
+         */
+        private String timeFormat = "HH:mm:ss";
+        /**
+         * The date-time format used for Json serialization/deserialization
+         */
+        private String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
         private Map models;
         /**
          * Defines the response model
@@ -669,6 +681,30 @@ public class ServiceNowComponentConfiguration
             this.proxyPassword = proxyPassword;
         }
 
+        public String getDateFormat() {
+            return dateFormat;
+        }
+
+        public void setDateFormat(String dateFormat) {
+            this.dateFormat = dateFormat;
+        }
+
+        public String getTimeFormat() {
+            return timeFormat;
+        }
+
+        public void setTimeFormat(String timeFormat) {
+            this.timeFormat = timeFormat;
+        }
+
+        public String getDateTimeFormat() {
+            return dateTimeFormat;
+        }
+
+        public void setDateTimeFormat(String dateTimeFormat) {
+            this.dateTimeFormat = dateTimeFormat;
+        }
+
         public Map getModels() {
             return models;
         }

Reply via email to