@@ -47,20 +47,29 @@ public class JEnum extends AbstractJSONSchema2Pojo {
47
47
private final String underlyingType ;
48
48
private final Set <String > values ; //Let's prevent duplicates
49
49
50
- public JEnum (String type , String underlyingType , List <JsonNode > values , Config config , String description ,
51
- final boolean isNullable ,
52
- JsonNode defaultValue ) {
50
+ // Used for matching against existing types.
51
+ private final String pkgPrefixedType ;
52
+
53
+ public JEnum (String pkg , String type , String underlyingType , List <JsonNode > values , Config config , String description ,
54
+ final boolean isNullable , JsonNode defaultValue ) {
53
55
super (config , description , isNullable , defaultValue , null );
54
56
this .type = AbstractJSONSchema2Pojo .sanitizeString (
55
57
type .substring (0 , 1 ).toUpperCase () + type .substring (1 ));
56
58
this .underlyingType = underlyingType ;
57
59
//Tests assume order so let's use LinkedHashSet instead of just using Collectors.toSet()
58
60
this .values = values .stream ().map (JsonNode ::asText ).collect (Collectors .toCollection (LinkedHashSet ::new ));
61
+ this .pkgPrefixedType = createPackagePrefixedType (pkg , this .type );
62
+ }
63
+
64
+ private String createPackagePrefixedType (String pkg , String type ) {
65
+ String p = (pkg == null ) ? "" : pkg .trim ();
66
+ String pkgPrefix = (p .isEmpty ()) ? p : p + "." ;
67
+ return pkgPrefix + type ;
59
68
}
60
69
61
70
@ Override
62
71
public String getType () {
63
- return this .type ;
72
+ return config . getExistingJavaTypes (). getOrDefault ( this .pkgPrefixedType , this . type ) ;
64
73
}
65
74
66
75
private String sanitizeEnumEntry (final String str ) {
@@ -93,6 +102,10 @@ private Statement generateBooleanCreator(boolean hasTrue, boolean hasFalse) {
93
102
94
103
@ Override
95
104
public GeneratorResult generateJava () {
105
+ if (config .getExistingJavaTypes ().containsKey (pkgPrefixedType )) {
106
+ return new GeneratorResult (Collections .emptyList ());
107
+ }
108
+
96
109
CompilationUnit cu = new CompilationUnit ();
97
110
EnumDeclaration en = cu .addEnum (this .type );
98
111
0 commit comments