@@ -115,18 +115,24 @@ public void processOpts() {
115
115
116
116
if ("feign" .equals (getLibrary ())) {
117
117
supportingFiles .add (new SupportingFile ("FormAwareEncoder.mustache" , invokerFolder , "FormAwareEncoder.java" ));
118
+ additionalProperties .put ("jackson" , "true" );
118
119
} else if ("okhttp-gson" .equals (getLibrary ())) {
119
120
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
120
121
supportingFiles .add (new SupportingFile ("ApiCallback.mustache" , invokerFolder , "ApiCallback.java" ));
121
122
supportingFiles .add (new SupportingFile ("ApiResponse.mustache" , invokerFolder , "ApiResponse.java" ));
122
123
supportingFiles .add (new SupportingFile ("JSON.mustache" , invokerFolder , "JSON.java" ));
123
124
supportingFiles .add (new SupportingFile ("ProgressRequestBody.mustache" , invokerFolder , "ProgressRequestBody.java" ));
124
125
supportingFiles .add (new SupportingFile ("ProgressResponseBody.mustache" , invokerFolder , "ProgressResponseBody.java" ));
126
+ additionalProperties .put ("gson" , "true" );
125
127
} else if (usesAnyRetrofitLibrary ()) {
126
128
supportingFiles .add (new SupportingFile ("auth/OAuthOkHttpClient.mustache" , authFolder , "OAuthOkHttpClient.java" ));
127
129
supportingFiles .add (new SupportingFile ("CollectionFormats.mustache" , invokerFolder , "CollectionFormats.java" ));
130
+ additionalProperties .put ("gson" , "true" );
128
131
} else if ("jersey2" .equals (getLibrary ())) {
129
132
supportingFiles .add (new SupportingFile ("JSON.mustache" , invokerFolder , "JSON.java" ));
133
+ additionalProperties .put ("jackson" , "true" );
134
+ } else if (StringUtils .isEmpty (getLibrary ())) {
135
+ additionalProperties .put ("jackson" , "true" );
130
136
}
131
137
}
132
138
@@ -171,32 +177,34 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
171
177
if (!BooleanUtils .toBoolean (model .isEnum )) {
172
178
final String lib = getLibrary ();
173
179
//Needed imports for Jackson based libraries
174
- if (StringUtils . isEmpty ( lib ) || "feign" . equals ( lib ) || "jersey2" . equals ( lib )) {
180
+ if (additionalProperties . containsKey ( "jackson" )) {
175
181
model .imports .add ("JsonProperty" );
176
182
177
- if (BooleanUtils .toBoolean (model .hasEnums )) {
183
+ /* if(BooleanUtils.toBoolean(model.hasEnums)) {
178
184
model.imports.add("JsonValue");
179
- }
185
+ }*/
186
+ }
187
+ if (additionalProperties .containsKey ("gson" )) {
188
+ model .imports .add ("SerializedName" );
180
189
}
181
190
}
182
191
}
183
192
184
193
@ Override
185
194
public Map <String , Object > postProcessModelsEnum (Map <String , Object > objs ) {
186
195
objs = super .postProcessModelsEnum (objs );
187
- String lib = getLibrary ();
188
- //Needed imports for Jackson based libraries
189
- if (StringUtils .isEmpty (lib ) || "feign" .equals (lib ) || "jersey2" .equals (lib )) {
196
+ //Needed import for Gson based libraries
197
+ if (additionalProperties .containsKey ("gson" )) {
190
198
List <Map <String , String >> imports = (List <Map <String , String >>)objs .get ("imports" );
191
199
List <Object > models = (List <Object >) objs .get ("models" );
192
200
for (Object _mo : models ) {
193
201
Map <String , Object > mo = (Map <String , Object >) _mo ;
194
202
CodegenModel cm = (CodegenModel ) mo .get ("model" );
195
203
// for enum model
196
204
if (Boolean .TRUE .equals (cm .isEnum ) && cm .allowableValues != null ) {
197
- cm .imports .add (importMapping .get ("JsonValue " ));
205
+ cm .imports .add (importMapping .get ("SerializedName " ));
198
206
Map <String , String > item = new HashMap <String , String >();
199
- item .put ("import" , importMapping .get ("JsonValue " ));
207
+ item .put ("import" , importMapping .get ("SerializedName " ));
200
208
imports .add (item );
201
209
}
202
210
}
0 commit comments