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 abd988ea9..14031d4ee 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/FormatRule.java @@ -26,6 +26,7 @@ import java.util.UUID; import java.util.regex.Pattern; +import org.apache.commons.lang3.ClassUtils; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalTime; @@ -165,7 +166,7 @@ private static Class getTimeType(GenerationConfig config) { private static Class tryLoadType(String typeName, String format) { if (!isEmpty(typeName)) { try { - Class type = Thread.currentThread().getContextClassLoader().loadClass(typeName); + Class type = ClassUtils.getClass(Thread.currentThread().getContextClassLoader(), typeName); return type; } catch (ClassNotFoundException e) { 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 index 44e1dd1f2..766870aa3 100644 --- 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 @@ -78,6 +78,17 @@ public void canOverrideNonStandardTypes() throws Exception { assertThat(getter.getReturnType(), typeCompatibleWith(URL.class)); } + @Test + public void canOverrideArrayTypes() throws Exception { + ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/format/arrayFormat.json", "com.example", + config("formatTypeMapping", mapping("base64", byte[].class))); + + Class generatedType = resultsClassLoader.loadClass("com.example.ArrayFormat"); + + Method getter = generatedType.getMethod("getArrayFormat"); + assertThat(getter.getReturnType(), typeCompatibleWith(byte[].class)); + } + private static Map mapping(Object... keyValues) { return config(keyValues) .entrySet() diff --git a/jsonschema2pojo-integration-tests/src/test/resources/schema/format/arrayFormat.json b/jsonschema2pojo-integration-tests/src/test/resources/schema/format/arrayFormat.json index 4815194ad..615a1e08b 100644 --- a/jsonschema2pojo-integration-tests/src/test/resources/schema/format/arrayFormat.json +++ b/jsonschema2pojo-integration-tests/src/test/resources/schema/format/arrayFormat.json @@ -1,9 +1,9 @@ { "type" : "object", "properties" : { - "stringAsNonStandard" : { + "arrayFormat" : { "type" : "string", - "format" : "non-standard" + "format" : "base64" } } }