[bug][Java] Honor instantiationMap for default values for array, map, set (#4982)

Co-authored-by: Jim Schubert <james.schubert@gmail.com>
This commit is contained in:
Marvin1912 2020-09-25 05:25:13 +02:00 committed by GitHub
parent 9778d970ac
commit 5f3d974a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -807,17 +807,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
if (ModelUtils.isArraySchema(schema)) { if (ModelUtils.isArraySchema(schema)) {
final String pattern; final String pattern;
if (ModelUtils.isSet(schema)) { if (ModelUtils.isSet(schema)) {
if (fullJavaUtil) { String mapInstantiationType = instantiationTypes().getOrDefault("set", "LinkedHashSet");
pattern = "new java.util.LinkedHashSet<%s>()"; pattern = "new " + mapInstantiationType + "<%s>()";
} else {
pattern = "new LinkedHashSet<%s>()";
}
} else { } else {
if (fullJavaUtil) { String arrInstantiationType = instantiationTypes().getOrDefault("array", "ArrayList");
pattern = "new java.util.ArrayList<%s>()"; pattern = "new " + arrInstantiationType + "<%s>()";
} else {
pattern = "new ArrayList<%s>()";
}
} }
Schema<?> items = getSchemaItems((ArraySchema) schema); Schema<?> items = getSchemaItems((ArraySchema) schema);
@ -840,12 +834,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
} }
return null; return null;
} }
final String pattern;
if (fullJavaUtil) { String mapInstantiationType = instantiationTypes().getOrDefault("map", "HashMap");
pattern = "new java.util.HashMap<%s>()"; final String pattern = "new " + mapInstantiationType + "<%s>()";
} else {
pattern = "new HashMap<%s>()";
}
if (getAdditionalProperties(schema) == null) { if (getAdditionalProperties(schema) == null) {
return null; return null;
} }