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 2f4ff887b..5e0a7f625 100644 --- a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java +++ b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java @@ -27,9 +27,13 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -177,6 +181,8 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig { private Language targetLanguage = Language.JAVA; + private Map formatTypeMapping = new HashMap<>(); + /** * Execute this task (it's expected that all relevant setters will have been * called by Ant to provide task configuration before this method @@ -871,6 +877,14 @@ public void setTargetLanguage(Language targetLanguage) { this.targetLanguage = targetLanguage; } + public void setFormatTypeMapping(Map formatTypeMapping) { + this.formatTypeMapping = formatTypeMapping; + } + public void setFormatTypeMapping(String[] formatTypeMapping) { + this.formatTypeMapping = Arrays.stream(formatTypeMapping) + .collect(Collectors.toMap(m -> m.split(":")[0], m -> m.split(":")[1])); + } + @Override public boolean isGenerateBuilders() { return generateBuilders; @@ -1182,5 +1196,10 @@ public SourceSortOrder getSourceSortOrder() { public Language getTargetLanguage() { return targetLanguage; } + + @Override + public Map getFormatTypeMapping() { + return formatTypeMapping; + } } diff --git a/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html b/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html index 647933a4b..5b823df1b 100644 --- a/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html +++ b/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html @@ -497,6 +497,13 @@

Parameters

No (default OS) + + formatTypeMapping + A mapping from format identifier (e.g. 'uri') to Java type (e.g. 'java.net.URI'): + >format<:>fully.qualified.Type<. + + None (default '' (none)) + 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 fef340dc3..f7b5f33de 100644 --- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java +++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java @@ -21,8 +21,11 @@ import java.io.File; import java.io.FileFilter; import java.net.URL; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import org.jsonschema2pojo.AllFileFilter; import org.jsonschema2pojo.AnnotationStyle; @@ -215,6 +218,9 @@ public class Arguments implements GenerationConfig { @Parameter(names = { "-tl", "--target-language" }, description = "The type of code that will be generated. Available options are: JAVA or SCALA") private Language targetLanguage = Language.JAVA; + + @Parameter(names = { "-ftm", "--format-type-mapping" }, description = "Mapping from format identifier to type: :.", variableArity = true) + private List formatTypeMapping = new ArrayList<>(); private static final int EXIT_OKAY = 0; private static final int EXIT_ERROR = 1; @@ -532,9 +538,16 @@ public String getCustomDateTimePattern() { public SourceSortOrder getSourceSortOrder() { return sourceSortOrder; } - + @Override public Language getTargetLanguage() { return targetLanguage; } + + @Override + public Map getFormatTypeMapping() { + return formatTypeMapping + .stream() + .collect(Collectors.toMap(m -> m.split(":")[0], m -> m.split(":")[1])); + } } diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java index a148fe244..d295b2690 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.FileFilter; import java.net.URL; +import java.util.Collections; import java.util.Iterator; +import java.util.Map; import org.jsonschema2pojo.rules.RuleFactory; @@ -434,5 +436,13 @@ public SourceSortOrder getSourceSortOrder() { public Language getTargetLanguage() { return Language.JAVA; } + + /** + * @return {@link Collections#emptyMap} + */ + @Override + public Map getFormatTypeMapping() { + return Collections.emptyMap(); + } } diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java index b05df9e4c..efcf91f5d 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java @@ -20,6 +20,7 @@ import java.io.FileFilter; import java.net.URL; import java.util.Iterator; +import java.util.Map; import org.jsonschema2pojo.rules.RuleFactory; @@ -562,5 +563,12 @@ public interface GenerationConfig { * */ Language getTargetLanguage(); - + + /** + * Gets the 'formatTypeMapping' configuration option. + * + * @return An optional mapping from format identifier (e.g. 'uri') to + * fully qualified type name (e.g. 'java.net.URI'). + */ + Map getFormatTypeMapping(); } 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 a6db88b70..abd988ea9 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java @@ -20,8 +20,9 @@ import static org.apache.commons.lang.StringUtils.*; import java.net.URI; -import java.net.URL; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import java.util.regex.Pattern; @@ -48,15 +49,17 @@ public class FormatRule implements Rule { public static String ISO_8601_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; private final RuleFactory ruleFactory; + private final Map> formatTypeMapping; protected FormatRule(RuleFactory ruleFactory) { this.ruleFactory = ruleFactory; + this.formatTypeMapping = getFormatTypeMapping(ruleFactory.getGenerationConfig()); } /** * Applies this schema rule to take the required code generation steps. *

- * This rule maps format values to Java types: + * This rule maps format values to Java types. By default: *

    *
  • "format":"date-time" => {@link java.util.Date} or {@link org.joda.time.DateTime} (if config useJodaDates is set) *
  • "format":"date" => {@link String} or {@link org.joda.time.LocalDate} (if config useJodaLocalDates is set) @@ -90,102 +93,86 @@ protected FormatRule(RuleFactory ruleFactory) { @Override public JType apply(String nodeName, JsonNode node, JsonNode parent, JType baseType, Schema schema) { - if (node.asText().equals("date-time")) { - return baseType.owner().ref(getDateTimeType()); - - } else if (node.asText().equals("date")) { - return baseType.owner().ref(getDateOnlyType()); - - } else if (node.asText().equals("time")) { - return baseType.owner().ref(getTimeOnlyType()); - - } else if (node.asText().equals("utc-millisec")) { - return unboxIfNecessary(baseType.owner().ref(Long.class), ruleFactory.getGenerationConfig()); - - } else if (node.asText().equals("regex")) { - return baseType.owner().ref(Pattern.class); - - } else if (node.asText().equals("color")) { - return baseType.owner().ref(String.class); - - } else if (node.asText().equals("style")) { - return baseType.owner().ref(String.class); - - } else if (node.asText().equals("phone")) { - return baseType.owner().ref(String.class); - - } else if (node.asText().equals("uri")) { - return baseType.owner().ref(URI.class); + Class type = getType(node.asText()); + if (type != null) { + JType jtype = baseType.owner().ref(type); + if (ruleFactory.getGenerationConfig().isUsePrimitives()) { + jtype = jtype.unboxify(); + } + return jtype; + } else { + return baseType; + } + } - } else if (node.asText().equals("email")) { - return baseType.owner().ref(String.class); + private Class getType(String format) { + return formatTypeMapping.getOrDefault(format, null); + } - } else if (node.asText().equals("ip-address")) { - return baseType.owner().ref(String.class); + private static Map> getFormatTypeMapping(GenerationConfig config) { + + Map> mapping = new HashMap<>(14); + mapping.put("date-time", getDateTimeType(config)); + mapping.put("date", getDateType(config)); + mapping.put("time", getTimeType(config)); + mapping.put("utc-millisec", Long.class); + mapping.put("regex", Pattern.class); + mapping.put("color", String.class); + mapping.put("style", String.class); + mapping.put("phone", String.class); + mapping.put("uri", URI.class); + mapping.put("email", String.class); + mapping.put("ip-address", String.class); + mapping.put("ipv6", String.class); + mapping.put("host-name", String.class); + mapping.put("uuid", UUID.class); + + for (Map.Entry override : config.getFormatTypeMapping().entrySet()) { + String format = override.getKey(); + Class type = tryLoadType(override.getValue(), format); + if (type != null) { + mapping.put(format, type); + } + } - } else if (node.asText().equals("ipv6")) { - return baseType.owner().ref(String.class); + return mapping; + } - } else if (node.asText().equals("host-name")) { - return baseType.owner().ref(String.class); - } - else if (node.asText().equals("uuid")) { - return baseType.owner().ref(UUID.class); - } - else { - return baseType; + private static Class getDateTimeType(GenerationConfig config) { + Class type = tryLoadType(config.getDateTimeType(), "data-time"); + if (type != null) { + return type; } - + return config.isUseJodaDates() ? DateTime.class : Date.class; } - private Class getDateTimeType() { - String type=ruleFactory.getGenerationConfig().getDateTimeType(); - if (!isEmpty(type)){ - try { - Class clazz=Thread.currentThread().getContextClassLoader().loadClass(type); - return clazz; - } - catch (ClassNotFoundException e) { - throw new GenerationException(format("could not load java type %s for date-time format", type), e); - } + private static Class getDateType(GenerationConfig config) { + Class type = tryLoadType(config.getDateType(), "data"); + if (type != null) { + return type; } - return ruleFactory.getGenerationConfig().isUseJodaDates() ? DateTime.class : Date.class; + return config.isUseJodaLocalDates() ? LocalDate.class : String.class; } - private Class getDateOnlyType() { - String type=ruleFactory.getGenerationConfig().getDateType(); - if (!isEmpty(type)){ - try { - Class clazz=Thread.currentThread().getContextClassLoader().loadClass(type); - return clazz; - } - catch (ClassNotFoundException e) { - throw new GenerationException(format("could not load java type %s for date format", type), e); - } + private static Class getTimeType(GenerationConfig config) { + Class type = tryLoadType(config.getTimeType(), "time"); + if (type != null) { + return type; } - return ruleFactory.getGenerationConfig().isUseJodaLocalDates() ? LocalDate.class : String.class; + return config.isUseJodaLocalTimes() ? LocalTime.class : String.class; } - private Class getTimeOnlyType() { - String type=ruleFactory.getGenerationConfig().getTimeType(); - if (!isEmpty(type)){ + private static Class tryLoadType(String typeName, String format) { + if (!isEmpty(typeName)) { try { - Class clazz=Thread.currentThread().getContextClassLoader().loadClass(type); - return clazz; + Class type = Thread.currentThread().getContextClassLoader().loadClass(typeName); + return type; } catch (ClassNotFoundException e) { - throw new GenerationException(format("could not load java type %s for time format", type), e); + throw new GenerationException(format("could not load java type %s for %s", typeName, format), e); } } - return ruleFactory.getGenerationConfig().isUseJodaLocalTimes() ? LocalTime.class : String.class; - } - - private JType unboxIfNecessary(JType type, GenerationConfig config) { - if (config.isUsePrimitives()) { - return type.unboxify(); - } else { - return type; - } + return null; } } diff --git a/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRuleJodaTest.java b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRuleJodaTest.java index 52b588a23..b6c04f21e 100644 --- a/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRuleJodaTest.java +++ b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRuleJodaTest.java @@ -43,7 +43,7 @@ public class FormatRuleJodaTest { private GenerationConfig config = mock(GenerationConfig.class); - private FormatRule rule = new FormatRule(new RuleFactory(config, new NoopAnnotator(), new SchemaStore())); + private FormatRule rule; private final String formatValue; private final Class expectedType; @@ -66,6 +66,7 @@ public void setupConfig() { when(config.isUseJodaLocalTimes()).thenReturn(true); when(config.isUseJodaLocalDates()).thenReturn(true); when(config.isUseJodaDates()).thenReturn(true); + rule = new FormatRule(new RuleFactory(config, new NoopAnnotator(), new SchemaStore())); } @Test diff --git a/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRulePrimitivesTest.java b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRulePrimitivesTest.java new file mode 100644 index 000000000..3866abc83 --- /dev/null +++ b/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/rules/FormatRulePrimitivesTest.java @@ -0,0 +1,83 @@ +/** + * Copyright © 2010-2017 Nokia + * + * Licensed 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.jsonschema2pojo.rules; + +import com.fasterxml.jackson.databind.node.TextNode; +import com.sun.codemodel.JCodeModel; +import com.sun.codemodel.JType; +import org.jsonschema2pojo.GenerationConfig; +import org.jsonschema2pojo.NoopAnnotator; +import org.jsonschema2pojo.SchemaStore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Collections; + +import static java.util.Arrays.asList; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(Parameterized.class) +public class FormatRulePrimitivesTest { + + private final GenerationConfig config = mock(GenerationConfig.class); + private final FormatRule rule; + + private final Class primitive; + private final Class wrapper; + + @Parameters + public static Collection data() { + return asList(new Object[][] { + { boolean.class, Boolean.class }, + { byte.class, Byte.class }, + { char.class, Character.class }, + { double.class, Double.class }, + { float.class, Float.class }, + { int.class, Integer.class }, + { long.class, Long.class }, + { short.class, Short.class }, + { void.class, Void.class }, + { null, BigDecimal.class }, + { null, String.class }}); + } + + public FormatRulePrimitivesTest(Class primitive, Class wrapper) { + this.primitive = primitive; + this.wrapper = wrapper; + + when(config.isUsePrimitives()).thenReturn(true); + when(config.getFormatTypeMapping()).thenReturn(Collections.singletonMap("test", wrapper.getName())); + rule = new FormatRule(new RuleFactory(config, new NoopAnnotator(), new SchemaStore())); + } + + @Test + public void usePrimitivesWithCustomTypeMapping() { + JType result = rule.apply("fooBar", TextNode.valueOf("test"), null, new JCodeModel().ref(Object.class), null); + + Class expected = primitive != null ? primitive : wrapper; + assertThat(result.fullName(), equalTo(expected.getName())); + assertThat(result.isPrimitive(), equalTo(primitive != null)); + } + +} 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 5f9e73b9e..55c68b790 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 @@ -90,6 +90,7 @@ public class JsonSchemaExtension implements GenerationConfig { String refFragmentPathDelimiters SourceSortOrder sourceSortOrder Language targetLanguage + Map formatTypeMapping public JsonSchemaExtension() { // See DefaultGenerationConfig @@ -144,6 +145,7 @@ public class JsonSchemaExtension implements GenerationConfig { formatDateTimes = false refFragmentPathDelimiters = "#/." sourceSortOrder = SourceSortOrder.OS + formatTypeMapping = Collections.emptyMap() } @Override @@ -165,10 +167,6 @@ public class JsonSchemaExtension implements GenerationConfig { annotationStyle = AnnotationStyle.valueOf(style.toUpperCase()) } - public void setUseTitleAsClassname(boolean useTitleAsClassname) { - useTitleAsClassname = useTitleAsClassname - } - public void setInclusionLevel(String level) { inclusionLevel = InclusionLevel.valueOf(level.toUpperCase()) } @@ -255,6 +253,7 @@ public class JsonSchemaExtension implements GenerationConfig { |refFragmentPathDelimiters = ${refFragmentPathDelimiters} |sourceSortOrder = ${sourceSortOrder} |targetLanguage = ${targetLanguage} + |formatTypeMapping = ${formatTypeMapping} """.stripMargin() } diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/FormatTypeMappingIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/FormatTypeMappingIT.java new file mode 100644 index 000000000..44e1dd1f2 --- /dev/null +++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/FormatTypeMappingIT.java @@ -0,0 +1,88 @@ +/** + * Copyright © 2010-2017 Nokia + * + * Licensed 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.jsonschema2pojo.integration.config; + +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import org.joda.time.LocalTime; +import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule; +import org.junit.Rule; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.net.URL; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import static org.hamcrest.Matchers.typeCompatibleWith; +import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.config; +import static org.junit.Assert.assertThat; + +public class FormatTypeMappingIT { + + @Rule public Jsonschema2PojoRule schemaRule = new Jsonschema2PojoRule(); + + @Test + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void canOverrideDateRelatedTypes() throws ClassNotFoundException, SecurityException, NoSuchMethodException { + + ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/format/formattedProperties.json", "com.example", + config("formatTypeMapping", mapping("date", LocalDate.class, "time", LocalTime.class, "date-time", DateTime.class))); + + Class generatedType = resultsClassLoader.loadClass("com.example.FormattedProperties"); + + Method dateTime = generatedType.getMethod("getStringAsDateTime"); + Method time = generatedType.getMethod("getStringAsTime"); + Method date = generatedType.getMethod("getStringAsDate"); + assertThat(dateTime.getReturnType(), typeCompatibleWith(DateTime.class)); + assertThat(time.getReturnType(), typeCompatibleWith(LocalTime.class)); + assertThat(date.getReturnType(), typeCompatibleWith(LocalDate.class)); + } + + @Test + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void canOverrideTypes() throws ClassNotFoundException, SecurityException, NoSuchMethodException { + + ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/format/formattedProperties.json", "com.example", + config("formatTypeMapping", mapping("uri", URL.class))); + + Class generatedType = resultsClassLoader.loadClass("com.example.FormattedProperties"); + + Method getter = generatedType.getMethod("getStringAsUri"); + assertThat(getter.getReturnType(), typeCompatibleWith(URL.class)); + } + + @Test + public void canOverrideNonStandardTypes() throws Exception { + ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/format/nonStandard.json", "com.example", + config("formatTypeMapping", mapping("non-standard", URL.class))); + + Class generatedType = resultsClassLoader.loadClass("com.example.NonStandard"); + + Method getter = generatedType.getMethod("getStringAsNonStandard"); + assertThat(getter.getReturnType(), typeCompatibleWith(URL.class)); + } + + private static Map mapping(Object... keyValues) { + return config(keyValues) + .entrySet() + .stream() + .collect(Collectors.toMap(Entry::getKey, e -> ((Class) e.getValue()).getName())); + } + +} diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/format/nonStandard.json b/jsonschema2pojo-integration-tests/src/test/resources/schema/format/nonStandard.json new file mode 100644 index 000000000..4815194ad --- /dev/null +++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/format/nonStandard.json @@ -0,0 +1,9 @@ +{ + "type" : "object", + "properties" : { + "stringAsNonStandard" : { + "type" : "string", + "format" : "non-standard" + } + } +} 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 a1992fd2f..b049cd4aa 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 @@ -25,8 +25,10 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.commons.io.FilenameUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; @@ -736,6 +738,13 @@ public class Jsonschema2PojoMojo extends AbstractMojo implements GenerationConfi */ private String targetLanguage = "java"; + /** + * @parameter property="jsonschema2pojo.formatTypeMapping" + * default-value="" + * @since 1.0.0 + */ + private Map formatTypeMapping = new HashMap<>(); + /** * Executes the plugin, to read the given source and behavioural properties * and generate POJOs. The current implementation acts as a wrapper around @@ -1145,4 +1154,9 @@ public SourceSortOrder getSourceSortOrder() { public Language getTargetLanguage() { return Language.valueOf(targetLanguage.toUpperCase()); } + + @Override + public Map getFormatTypeMapping() { + return formatTypeMapping; + } }