Repository: joelittlejohn/jsonschema2pojo
Pull request #740 (2017-06-04 15:47:16)

Added support for formatting times
The default format is HH:mm:ss.SSS and can be overridden by
specifying a customTimePattern property.


Patch:
diff --git a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
index dbc89db5..14258a3e 100644
--- a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
+++ b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
@@ -151,8 +151,12 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig {
 
     private boolean formatDates = false;
 
+    private boolean formatTimes = false;
+
     private String customDatePattern;
 
+    private String customTimePattern;
+
     private String customDateTimePattern;
 
     private String refFragmentPathDelimiters = "#/.";
@@ -708,6 +712,17 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig {
         this.formatDateTimes = formatDateTimes;
     }
 
+    /**
+     * Sets the 'formatTimes' property of this class
+     *
+     * @param formatTimes
+     *            Whether the fields of type <code>time</code> have the <code>@JsonFormat</code> annotation
+     *            with pattern set to the default value of <code>HH:mm:ss.SSS</code>.
+     */
+    public void setFormatTimes(boolean formatTimes) {
+        this.formatTimes = formatTimes;
+    }
+
     /**
      * Sets the 'formatDates' property of this class
      *
@@ -731,6 +746,18 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig {
         this.customDatePattern = customDatePattern;
     }
 
+    /**
+     * Sets the 'customTimePattern' property of this class
+     *
+     * @param customTimePattern
+     *            A custom pattern to use when formatting time fields during
+     *            serialization. Requires support from your JSON binding
+     *            library.
+     */
+    public void setCustomTimePattern(String customTimePattern) {
+        this.customTimePattern = customTimePattern;
+    }
+
     /**
      * Sets the 'customDateTimePattern' property of this class
      *
@@ -1016,11 +1043,21 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig {
         return formatDates;
     }
 
+    @Override
+    public boolean isFormatTimes() {
+        return formatTimes;
+    }
+
     @Override
     public String getCustomDatePattern() {
         return customDatePattern;
     }
 
+    @Override
+    public String getCustomTimePattern() {
+        return customTimePattern;
+    }
+
     @Override
     public String getCustomDateTimePattern() {
         return customDateTimePattern;
diff --git a/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html b/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html
index 5a8dc711..1ec6833b 100644
--- a/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html
+++ b/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html
@@ -411,6 +411,12 @@
         </td>
         <td align="center" valign="top">No (default <code>false</code>)</td>
     </tr>
+    <tr>
+        <td valign="top">formatTimes</td>
+        <td valign="top">Whether the fields of type `time` are formatted during serialization with a default pattern of HH:mm:ss.SSS.
+        </td>
+        <td align="center" valign="top">No (default <code>false</code>)</td>
+    </tr>
     <tr>
         <td valign="top">formatDateTimes</td>
         <td valign="top">Whether the fields of type `date` are formatted during serialization with a default pattern of yyyy-MM-dd'T'HH:mm:ss.SSSZ.
@@ -423,6 +429,12 @@
         </td>
         <td align="center" valign="top">No (default none)</td>
     </tr>
+    <tr>
+        <td valign="top">customTimePattern</td>
+        <td valign="top">A custom pattern to use when formatting time fields during serialization. Requires support from your JSON binding library.
+        </td>
+        <td align="center" valign="top">No (default none)</td>
+    </tr>
     <tr>
         <td valign="top">customDateTimePattern</td>
         <td valign="top">A custom pattern to use when formatting date fields during serialization. Requires support from your JSON binding library.
diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
index 37433e90..51fac8a5 100644
--- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
+++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
@@ -173,12 +173,18 @@ public class Arguments implements GenerationConfig {
     @Parameter(names = { "-fd", "--format-dates" }, description = "Whether the fields of type `date` are formatted during serialization with a default pattern of `yyyy-MM-dd`")
     private boolean formatDates = false;
 
+    @Parameter(names = { "-ft", "--format-times" }, description = "Whether the fields of type `time` are formatted during serialization with a default pattern of `HH:mm:ss.SSS`")
+    private boolean formatTimes = false;
+
     @Parameter(names = { "-fdt", "--format-date-times" }, description = "Whether the fields of type `date-time` are formatted during serialization with a default pattern of `yyyy-MM-dd'T'HH:mm:ss.SSSZ` and timezone set to default value of `UTC`")
     private boolean formatDateTimes = false;
 
     @Parameter(names = { "-dp", "--date-pattern" }, description = "A custom pattern to use when formatting date fields during serialization")
     private String customDatePattern;
 
+    @Parameter(names = { "-tp", "--time-pattern" }, description = "A custom pattern to use when formatting time fields during serialization")
+    private String customTimePattern;
+
     @Parameter(names = { "-dtp", "--date-time-pattern" }, description = "A custom pattern to use when formatting date-time fields during serialization")
     private String customDateTimePattern;
 
@@ -448,6 +454,11 @@ public class Arguments implements GenerationConfig {
         return formatDates;
     }
 
+    @Override
+    public boolean isFormatTimes() {
+        return formatTimes;
+    }
+
     @Override
     public String getRefFragmentPathDelimiters() {
         return refFragmentPathDelimiters;
@@ -458,6 +469,11 @@ public class Arguments implements GenerationConfig {
         return customDatePattern;
     }
 
+    @Override
+    public String getCustomTimePattern() {
+        return customTimePattern;
+    }
+
     @Override
     public String getCustomDateTimePattern() {
         return customDateTimePattern;
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/AbstractAnnotator.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/AbstractAnnotator.java
index 4963d2ef..ccd5bc98 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/AbstractAnnotator.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/AbstractAnnotator.java
@@ -99,6 +99,10 @@ public abstract class AbstractAnnotator implements Annotator {
     public void dateField(JFieldVar field, JsonNode node) {
     }
 
+    @Override
+    public void timeField(JFieldVar field, JsonNode node) {
+    }
+
     @Override
     public void dateTimeField(JFieldVar field, JsonNode node) {
     }
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Annotator.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Annotator.java
index c35b0586..baba8479 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Annotator.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Annotator.java
@@ -183,5 +183,16 @@ public interface Annotator {
      */
     void dateField(JFieldVar field, JsonNode propertyNode);
 
+    /**
+     * Add the necessary annotations to a time field. For instance, to format
+     * the time in the expected style.
+     *
+     * @param field
+     *            the field that contains data that will be serialized
+     * @param propertyNode
+     *            the schema node defining this property
+     */
+    void timeField(JFieldVar field, JsonNode propertyNode);
+
     void additionalPropertiesField(JFieldVar field, JDefinedClass clazz, String propertyName);
 }
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/CompositeAnnotator.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/CompositeAnnotator.java
index 31515cf1..c587e232 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/CompositeAnnotator.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/CompositeAnnotator.java
@@ -143,4 +143,11 @@ public class CompositeAnnotator implements Annotator {
             annotator.dateField(field, propertyNode);
         }
    }
+
+    @Override
+    public void timeField(JFieldVar field, JsonNode propertyNode) {
+        for (Annotator annotator : annotators) {
+            annotator.timeField(field, propertyNode);
+        }
+    }
 }
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java
index f00f3dd8..9d88ad52 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java
@@ -353,6 +353,14 @@ public class DefaultGenerationConfig implements GenerationConfig {
         return false;
     }
 
+    /**
+     * @return <code>false</code>
+     */
+    @Override
+    public boolean isFormatTimes() {
+        return false;
+    }
+
     /**
      * @return "#/."
      */
@@ -366,6 +374,11 @@ public class DefaultGenerationConfig implements GenerationConfig {
         return null;
     }
 
+    @Override
+    public String getCustomTimePattern() {
+        return null;
+    }
+
     @Override
     public String getCustomDateTimePattern() {
         return null;
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java
index 386e7e8b..6a2cef1b 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java
@@ -449,6 +449,15 @@ public interface GenerationConfig {
      */
     boolean isFormatDates();
 
+    /**
+     * Gets the `formatTimes` configuration option
+     *
+     * @return Whether the fields of type <code>time</code> have the
+     *         <code>@JsonFormat</code> annotation with pattern set to the
+     *         default value of <code>HH:mm:ss.SSS</code>
+     */
+    boolean isFormatTimes();
+
     /**
      * Gets the `formatDateTime` configuration option
      *
@@ -466,6 +475,14 @@ public interface GenerationConfig {
      */
     String getCustomDatePattern();
 
+    /**
+     * Gets the 'customTimePattern' configuration option
+     *
+     * @return The custom format that times will use when types are serialized.
+     *         Requires support from your JSON binding library.
+     */
+    String getCustomTimePattern();
+
     /**
      * Gets the 'customDateTimePattern' configuration option
      *
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jackson2Annotator.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jackson2Annotator.java
index 11093d21..427a9dbd 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jackson2Annotator.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jackson2Annotator.java
@@ -175,6 +175,25 @@ public class Jackson2Annotator extends AbstractAnnotator {
         }
     }
 
+    @Override
+    public void timeField(JFieldVar field, JsonNode node) {
+
+        String pattern = null;
+        if (node.has("customTimePattern")) {
+            pattern = node.get("customTimePattern").asText();
+        } else if (node.has("customPattern")) {
+            pattern = node.get("customPattern").asText();
+        } else if (isNotEmpty(getGenerationConfig().getCustomTimePattern())) {
+            pattern = getGenerationConfig().getCustomTimePattern();
+        } else if (getGenerationConfig().isFormatDates()) {
+            pattern = FormatRule.ISO_8601_TIME_FORMAT;
+        }
+
+        if (pattern != null && !field.type().fullName().equals("java.lang.String")) {
+            field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern);
+        }
+    }
+
     @Override
     public void dateTimeField(JFieldVar field, JsonNode node) {
         String timezone = node.has("customTimezone") ? node.get("customTimezone").asText() : "UTC";
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java
index 2d5c0ed8..b06a98af 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java
@@ -43,6 +43,7 @@ import com.sun.codemodel.JType;
 public class FormatRule implements Rule<JType, JType> {
 
     public static String ISO_8601_DATE_FORMAT = "yyyy-MM-dd";
+    public static String ISO_8601_TIME_FORMAT = "HH:mm:ss.SSS";
     public static String ISO_8601_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
 
     private final RuleFactory ruleFactory;
diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java
index ba237bee..3b47007c 100644
--- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java
+++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java
@@ -144,6 +144,8 @@ public class PropertyRule implements Rule<JDefinedClass, JDefinedClass> {
             ruleFactory.getAnnotator().dateTimeField(field, node);
         } else if ("date".equalsIgnoreCase(format)) {
             ruleFactory.getAnnotator().dateField(field, node);
+        } else if ("time".equalsIgnoreCase(format)) {
+            ruleFactory.getAnnotator().timeField(field, node);
         }
     }
 
diff --git a/jsonschema2pojo-gradle-plugin/README.md b/jsonschema2pojo-gradle-plugin/README.md
index d9676700..fc7f7ce8 100644
--- a/jsonschema2pojo-gradle-plugin/README.md
+++ b/jsonschema2pojo-gradle-plugin/README.md
@@ -136,12 +136,13 @@ jsonSchema2Pojo {
   // date type fields to generated Java types.
   useJodaDates = false
 
-  // Whether to add JsonFormat annotations when using Jackson 2 that cause format "date" and "date-time"
-  // fields to be formatted as yyyy-MM-dd and yyyy-MM-dd'T'HH:mm:ss.SSSZ respectively. To customize these
-  // patterns, use customDatePattern and customDateTimePattern config options or add these inside a schema
-  // to affect an individual field
+  // Whether to add JsonFormat annotations when using Jackson 2 that cause format "date", "time", and "date-time"
+  // fields to be formatted as yyyy-MM-dd, HH:mm:ss.SSS and yyyy-MM-dd'T'HH:mm:ss.SSSZ respectively. To customize these
+  // patterns, use customDatePattern, customTimePattern, and customDateTimePattern config options or add these inside a 
+  // schema to affect an individual field
   formatDateTimes = true
   formatDates = true
+  formatTimes = true
     
   // Whether to use commons-lang 3.x imports instead of commons-lang 2.x imports when adding equals, 
   // hashCode and toString methods.
diff --git a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy
index 38baa52b..362f9fdb 100644
--- a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy
+++ b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy
@@ -75,8 +75,10 @@ public class JsonSchemaExtension implements GenerationConfig {
   boolean usePrimitives
   FileFilter fileFilter
   boolean formatDates
+  boolean formatTimes
   boolean formatDateTimes
   String customDatePattern
+  String customTimePattern
   String customDateTimePattern
   String refFragmentPathDelimiters
   SourceSortOrder sourceSortOrder
@@ -124,6 +126,7 @@ public class JsonSchemaExtension implements GenerationConfig {
     targetVersion = '1.6'
     includeDynamicAccessors = false
     formatDates = false
+    formatTimes = false
     formatDateTimes = false
     refFragmentPathDelimiters = "#/."
     sourceSortOrder = SourceSortOrder.OS
@@ -217,8 +220,10 @@ public class JsonSchemaExtension implements GenerationConfig {
        |targetVersion = ${targetVersion}
        |includeDynamicAccessors = ${includeDynamicAccessors}
        |formatDates = ${formatDates}
+       |formatTimes = ${formatTimes}
        |formatDateTimes = ${formatDateTimes}
        |customDatePattern = ${customDatePattern}
+       |customTimePattern = ${customTimePattern}
        |customDateTimePattern = ${customDateTimePattern}
        |refFragmentPathDelimiters = ${refFragmentPathDelimiters}
        |sourceSortOrder = ${sourceSortOrder}
diff --git a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java
index cc214f20..eb95998d 100644
--- a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java
+++ b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java
@@ -588,6 +588,16 @@ public class Jsonschema2PojoMojo extends AbstractMojo implements GenerationConfi
      */
     private boolean formatDates = false;
 
+    /**
+     * Whether the fields of type `time` are formatted during serialization with
+     * a default pattern of HH:mm:ss.SSS.
+     *
+     * @parameter expression="${jsonschema2pojo.formatTimes}"
+     *            default-value="false"
+     * @since 0.4.33
+     */
+    private boolean formatTimes = false;
+
     /**
      * Whether the fields of type `date` are formatted during serialization with
      * a default pattern of yyyy-MM-dd'T'HH:mm:ss.SSSZ.
@@ -607,6 +617,15 @@ public class Jsonschema2PojoMojo extends AbstractMojo implements GenerationConfi
      */
     private String customDatePattern;
 
+    /**
+     * A custom pattern to use when formatting time fields during serialization.
+     * Requires support from your JSON binding library.
+     *
+     * @parameter expression "${jsonschema2pojo.customTimePattern}"
+     * @since 0.4.33
+     */
+    private String customTimePattern;
+
     /**
      * A custom pattern to use when formatting date-time fields during
      * serialization. Requires support from your JSON binding library.
@@ -990,11 +1009,21 @@ public class Jsonschema2PojoMojo extends AbstractMojo implements GenerationConfi
         return formatDates;
     }
 
+    @Override
+    public boolean isFormatTimes() {
+        return formatTimes;
+    }
+
     @Override
     public String getCustomDatePattern() {
         return customDatePattern;
     }
 
+    @Override
+    public String getCustomTimePattern() {
+        return customTimePattern;
+    }
+
     @Override
     public String getCustomDateTimePattern() {
         return customDateTimePattern;


Test patch:
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/CustomDateTimeFormatIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/CustomDateTimeFormatIT.java
index d4d3daca..5411b2bb 100644
--- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/CustomDateTimeFormatIT.java
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/CustomDateTimeFormatIT.java
@@ -44,20 +44,27 @@ public class CustomDateTimeFormatIT {
 
         classSchemaRule.generate("/schema/format/customDateTimeFormat.json", "com.example.config_true", config(
                 "dateType", "java.util.Date",
+                "timeType", "java.util.Date",
                 "formatDateTimes", Boolean.TRUE,
-                "formatDates", Boolean.TRUE));
+                "formatDates", Boolean.TRUE,
+                "formatTimes", Boolean.TRUE));
 
         classSchemaRule.generate("/schema/format/customDateTimeFormat.json", "com.example.config_false", config(
                 "dateType", "java.util.Date",
+                "timeType", "java.util.Date",
                 "formatDateTimes", Boolean.FALSE,
+                "formatDates", Boolean.FALSE,
                 "formatDates", Boolean.FALSE));
 
         classSchemaRule.generate("/schema/format/customDateTimeFormat.json", "com.example.config_custom", config(
                 "dateType", "java.util.Date",
+                "timeType", "java.util.Date",
                 "customDatePattern", "yyyy",
+                "customTimePattern", "H:mm a",
                 "customDateTimePattern", "yyyy-MM-dd HH:mm X",
                 "formatDateTimes", Boolean.TRUE,
-                "formatDates", Boolean.TRUE));
+                "formatDates", Boolean.TRUE,
+                "formatTimes", Boolean.TRUE));
 
         ClassLoader loader = classSchemaRule.compile();
 
@@ -170,6 +177,16 @@ public class CustomDateTimeFormatIT {
         assertThat(json, is("{\"defaultFormatDate\":\"2001-09-09\"}"));
     }
 
+    @Test
+    public void testDefaultWhenFormatTimesConfigIsTrue() throws ReflectiveOperationException, SecurityException, JsonProcessingException {
+        final Object instance = classWhenFormatDatesTrue.newInstance();
+        classWhenFormatDatesTrue.getMethod("setDefaultFormatTime", Date.class).invoke(instance, new Date(999999999999L));
+
+        final String json = new ObjectMapper().writeValueAsString(instance);
+
+        assertThat(json, is("{\"defaultFormatTime\":\"01:46:39.999\"}"));
+    }
+
     @Test
     public void testDefaultWhenFormatDatesConfigIsFalse() throws ReflectiveOperationException, SecurityException, JsonProcessingException {
         final Object instance = classWhenFormatDatesFalse.newInstance();
@@ -180,6 +197,16 @@ public class CustomDateTimeFormatIT {
         assertThat(json, is("{\"defaultFormatDate\":999999999999}"));
     }
 
+    @Test
+    public void testDefaultWhenFormatTimesConfigIsFalse() throws ReflectiveOperationException, SecurityException, JsonProcessingException {
+        final Object instance = classWhenFormatDatesFalse.newInstance();
+        classWhenFormatDatesFalse.getMethod("setDefaultFormatTime", Date.class).invoke(instance, new Date(999999999999L));
+
+        final String json = new ObjectMapper().writeValueAsString(instance);
+
+        assertThat(json, is("{\"defaultFormatTime\":999999999999}"));
+    }
+
     @Test
     public void testCustomDatePattern() throws ReflectiveOperationException, SecurityException, JsonProcessingException {
         final Object instance = classWhenFormatDatesTrue.newInstance();
@@ -189,4 +216,14 @@ public class CustomDateTimeFormatIT {
 
         assertThat(json, is("{\"customFormatCustomDate\":\"09-09-2001\"}"));
     }
+
+    @Test
+    public void testCustomTimePattern() throws ReflectiveOperationException, SecurityException, JsonProcessingException {
+        final Object instance = classWhenFormatDatesTrue.newInstance();
+        classWhenFormatDatesTrue.getMethod("setCustomFormatCustomTime", Date.class).invoke(instance, new Date(999999999999L));
+
+        final String json = new ObjectMapper().writeValueAsString(instance);
+
+        assertThat(json, is("{\"customFormatCustomTime\":\"1:46 AM\"}"));
+    }
 }
diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/CustomAnnotatorIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/CustomAnnotatorIT.java
index 27285baf..12ff2027 100644
--- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/CustomAnnotatorIT.java
+++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/CustomAnnotatorIT.java
@@ -177,6 +177,11 @@ public class CustomAnnotatorIT {
             field.annotate(Deprecated.class);
         }
 
+        @Override
+        public void timeField(JFieldVar field, JsonNode propertyNode) {
+            field.annotate(Deprecated.class);
+        }
+
         @Override
         public void dateTimeField(JFieldVar field, JsonNode propertyNode) {
             field.annotate(Deprecated.class);
diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/format/customDateTimeFormat.json b/jsonschema2pojo-integration-tests/src/test/resources/schema/format/customDateTimeFormat.json
index f9792ca1..f55de969 100644
--- a/jsonschema2pojo-integration-tests/src/test/resources/schema/format/customDateTimeFormat.json
+++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/format/customDateTimeFormat.json
@@ -25,10 +25,19 @@
             "type" : "string",
             "format" : "date"
         },
+        "defaultFormatTime" : {
+            "type": "string",
+            "format": "time"
+        },
         "customFormatCustomDate" : {
             "type" : "string",
             "format" : "date",
             "customDatePattern" : "dd-MM-yyyy"
+        },
+        "customFormatCustomTime" : {
+            "type" : "string",
+            "format" : "time",
+            "customTimePattern" : "H:mm a"
         }
     }
 }
\ No newline at end of file