Skip to content

Commit

Permalink
fix for #1043: formatTypeMapping error on array classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kullanici0606 committed Nov 17, 2019
1 parent cdcc92c commit 960cb98
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> mapping(Object... keyValues) {
return config(keyValues)
.entrySet()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type" : "object",
"properties" : {
"stringAsNonStandard" : {
"arrayFormat" : {
"type" : "string",
"format" : "non-standard"
"format" : "base64"
}
}
}

0 comments on commit 960cb98

Please sign in to comment.