Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit cec23db

Browse files
shalousunlinwumingshi
authored andcommitted
fix: fix the key type check error for map types
1 parent 0446bf6 commit cec23db

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/main/java/com/ly/doc/helper/JsonBuildHelper.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,14 @@ public static void buildMapJson(String genericCanonicalName, boolean isResp, int
545545
}
546546
JavaClass mapKeyClass = builder.getJavaProjectBuilder().getClassByName(getKeyValType[0]);
547547
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]);
548+
String keyType = getKeyValType[0];
549+
550+
if (builder.getApiConfig().isStrict()) {
551+
boolean isStringKey = JavaTypeConstants.JAVA_STRING_FULLY.equals(keyType);
552+
boolean isValidEnumKey = mapKeyIsEnum && !mapKeyClass.getEnumConstants().isEmpty();
553+
if (!isStringKey && !isValidEnumKey) {
554+
throw new RuntimeException("Map's key can only use String or Enum for JSON, but you used: " + keyType);
555+
}
552556
}
553557
String gicName = getKeyValType[1];
554558
// when map key is enum

0 commit comments

Comments
 (0)