@@ -287,8 +287,6 @@ else if (JavaClassValidateUtil.isReactor(typeName)) {
287287
288288 // get tags value from the field
289289 Map <String , String > tagsMap = DocUtil .getFieldTagsValue (field , docField );
290- // get annotations on the field
291- List <JavaAnnotation > annotations = docField .getAnnotations ();
292290
293291 // field json annotation
294292 FieldJsonAnnotationInfo annotationInfo = getFieldJsonAnnotationInfo (projectBuilder , docField , isResp ,
@@ -301,7 +299,7 @@ else if (JavaClassValidateUtil.isReactor(typeName)) {
301299 String fieldJsonFormatValue = annotationInfo .getFieldJsonFormatValue ();
302300 // has Annotation @JsonSerialize And using ToStringSerializer
303301 boolean toStringSerializer = Boolean .TRUE .equals (annotationInfo .getToStringSerializer ());
304- if (Objects . nonNull (annotationInfo .getFieldName ())) {
302+ if (StringUtil . isNotEmpty (annotationInfo .getFieldName ())) {
305303 fieldName = annotationInfo .getFieldName ();
306304 }
307305
@@ -545,10 +543,14 @@ public static void buildMapJson(String genericCanonicalName, boolean isResp, int
545543 }
546544 JavaClass mapKeyClass = builder .getJavaProjectBuilder ().getClassByName (getKeyValType [0 ]);
547545 boolean mapKeyIsEnum = mapKeyClass .isEnum ();
548- if ((!JavaTypeConstants .JAVA_STRING_FULLY .equals (getKeyValType [0 ]) || !mapKeyIsEnum
549- || mapKeyClass .getEnumConstants ().isEmpty ()) && builder .getApiConfig ().isStrict ()) {
550- throw new RuntimeException (
551- "Map's key can only use String or Enum for json,but you use " + getKeyValType [0 ]);
546+ String keyType = getKeyValType [0 ];
547+
548+ if (builder .getApiConfig ().isStrict ()) {
549+ boolean isStringKey = JavaTypeConstants .JAVA_STRING_FULLY .equals (keyType );
550+ boolean isValidEnumKey = mapKeyIsEnum && !mapKeyClass .getEnumConstants ().isEmpty ();
551+ if (!isStringKey && !isValidEnumKey ) {
552+ throw new RuntimeException ("Map's key can only use String or Enum for JSON, but you used: " + keyType );
553+ }
552554 }
553555 String gicName = getKeyValType [1 ];
554556 // when map key is enum
0 commit comments