diff --git a/packages/quicktype-core/src/language/Java/utils.ts b/packages/quicktype-core/src/language/Java/utils.ts index 8e27c72b6..48827f4c1 100644 --- a/packages/quicktype-core/src/language/Java/utils.ts +++ b/packages/quicktype-core/src/language/Java/utils.ts @@ -44,13 +44,15 @@ export function javaNameStyle( upperUnderscore ? allUpperWordStyle : startWithUpper - ? firstUpperWordStyle - : allLowerWordStyle, + ? firstUpperWordStyle + : allLowerWordStyle, upperUnderscore ? allUpperWordStyle : firstUpperWordStyle, upperUnderscore || startWithUpper ? allUpperWordStyle : allLowerWordStyle, - acronymsStyle, + // For UPPER_UNDERSCORE style (Java enum constants), always use allUpperWordStyle for acronyms + // to maintain consistency with the naming convention (e.g., XXX_SPA_XXX) + upperUnderscore ? allUpperWordStyle : acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter, ); diff --git a/test/fixtures/java/src/main/java/io/quicktype/MessageCode.java b/test/fixtures/java/src/main/java/io/quicktype/MessageCode.java new file mode 100644 index 000000000..4d113ae8f --- /dev/null +++ b/test/fixtures/java/src/main/java/io/quicktype/MessageCode.java @@ -0,0 +1,42 @@ +package io.quicktype; + +import java.io.IOException; +import com.fasterxml.jackson.annotation.*; + +public class MessageCode { + private Code code; + + @JsonProperty("code") + public Code getCode() { + return code; + } + + @JsonProperty("code") + public void setCode(Code value) { + this.code = value; + } + + public enum Code { + MULTI_SPA_IN_GROUP_REJECTED, SOME_OTHER_VALUE; + + @JsonValue + public String toValue() { + switch (this) { + case MULTI_SPA_IN_GROUP_REJECTED: + return "MULTI_SPA_IN_GROUP_REJECTED"; + case SOME_OTHER_VALUE: + return "SOME_OTHER_VALUE"; + } + return null; + } + + @JsonCreator + public static Code forValue(String value) throws IOException { + if (value.equals("MULTI_SPA_IN_GROUP_REJECTED")) + return MULTI_SPA_IN_GROUP_REJECTED; + if (value.equals("SOME_OTHER_VALUE")) + return SOME_OTHER_VALUE; + throw new IOException("Cannot deserialize Code"); + } + } +} diff --git a/test/inputs/json/priority/enum-spa.json b/test/inputs/json/priority/enum-spa.json new file mode 100644 index 000000000..ce5b3aeb3 --- /dev/null +++ b/test/inputs/json/priority/enum-spa.json @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "code": { + "type": "string", + "enum": ["SOME_OTHER_VALUE", "MULTI_SPA_IN_GROUP_REJECTED"] + } + } +}