From 7ba218d61bfb9caf3a0eb108cbed9201736f5478 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Thu, 16 Jul 2026 10:31:49 +0200 Subject: [PATCH] Use declaring enum class for Jackson names Jackson enum identifiers used the runtime constant class, which is an anonymous subclass for enum constants with class bodies. Build identifiers from the declaring enum class in both Jackson adapters and cover lookup/native conversion for a constant-specific class body. --- .../cel/types/jackson/JacksonEnumValue.java | 2 +- .../jackson/Jackson2TypeDescriptionTest.java | 12 ++++++++ .../jackson/types/EnumWithConstantBody.java | 30 +++++++++++++++++++ .../cel/types/jackson3/JacksonEnumValue.java | 2 +- .../jackson3/Jackson3TypeDescriptionTest.java | 12 ++++++++ .../jackson3/types/EnumWithConstantBody.java | 30 +++++++++++++++++++ 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 jackson/src/test/java/org/projectnessie/cel/types/jackson/types/EnumWithConstantBody.java create mode 100644 jackson3/src/test/java/org/projectnessie/cel/types/jackson3/types/EnumWithConstantBody.java diff --git a/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonEnumValue.java b/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonEnumValue.java index dc99fdd6..52b51643 100644 --- a/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonEnumValue.java +++ b/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonEnumValue.java @@ -30,7 +30,7 @@ final class JacksonEnumValue { } static String fullyQualifiedName(Enum value) { - return value.getClass().getName().replace('$', '.') + '.' + value.name(); + return value.getDeclaringClass().getName().replace('$', '.') + '.' + value.name(); } String fullyQualifiedName() { diff --git a/jackson/src/test/java/org/projectnessie/cel/types/jackson/Jackson2TypeDescriptionTest.java b/jackson/src/test/java/org/projectnessie/cel/types/jackson/Jackson2TypeDescriptionTest.java index 44c4527a..8a9d0c5c 100644 --- a/jackson/src/test/java/org/projectnessie/cel/types/jackson/Jackson2TypeDescriptionTest.java +++ b/jackson/src/test/java/org/projectnessie/cel/types/jackson/Jackson2TypeDescriptionTest.java @@ -52,6 +52,7 @@ import org.projectnessie.cel.common.types.ref.Val; import org.projectnessie.cel.types.jackson.types.AnEnum; import org.projectnessie.cel.types.jackson.types.CollectionsObject; +import org.projectnessie.cel.types.jackson.types.EnumWithConstantBody; import org.projectnessie.cel.types.jackson.types.InnerType; class Jackson2TypeDescriptionTest { @@ -117,6 +118,17 @@ void basics() { .isInstanceOf(IllegalArgumentException.class); } + @Test + void enumConstantSpecificClassBodyUsesDeclaringClassName() { + JacksonRegistry reg = (JacksonRegistry) newRegistry(); + reg.enumDescription(EnumWithConstantBody.class); + + assertThat(reg.findIdent(EnumWithConstantBody.class.getName() + ".SPECIAL")) + .isEqualTo(intOf(EnumWithConstantBody.SPECIAL.ordinal())); + assertThat(reg.nativeToValue(EnumWithConstantBody.SPECIAL)) + .isEqualTo(intOf(EnumWithConstantBody.SPECIAL.ordinal())); + } + @Test void types() { JacksonRegistry reg = (JacksonRegistry) newRegistry(); diff --git a/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/EnumWithConstantBody.java b/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/EnumWithConstantBody.java new file mode 100644 index 00000000..a5851075 --- /dev/null +++ b/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/EnumWithConstantBody.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2026 The Authors of CEL-Java + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.projectnessie.cel.types.jackson.types; + +public enum EnumWithConstantBody { + DEFAULT, + SPECIAL { + @Override + public String label() { + return "special"; + } + }; + + public String label() { + return name(); + } +} diff --git a/jackson3/src/main/java/org/projectnessie/cel/types/jackson3/JacksonEnumValue.java b/jackson3/src/main/java/org/projectnessie/cel/types/jackson3/JacksonEnumValue.java index e0bb1255..db86ac1f 100644 --- a/jackson3/src/main/java/org/projectnessie/cel/types/jackson3/JacksonEnumValue.java +++ b/jackson3/src/main/java/org/projectnessie/cel/types/jackson3/JacksonEnumValue.java @@ -30,7 +30,7 @@ final class JacksonEnumValue { } static String fullyQualifiedName(Enum value) { - return value.getClass().getName().replace('$', '.') + '.' + value.name(); + return value.getDeclaringClass().getName().replace('$', '.') + '.' + value.name(); } String fullyQualifiedName() { diff --git a/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/Jackson3TypeDescriptionTest.java b/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/Jackson3TypeDescriptionTest.java index 854aacc2..6ee91bff 100644 --- a/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/Jackson3TypeDescriptionTest.java +++ b/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/Jackson3TypeDescriptionTest.java @@ -51,6 +51,7 @@ import org.projectnessie.cel.common.types.ref.Val; import org.projectnessie.cel.types.jackson3.types.AnEnum; import org.projectnessie.cel.types.jackson3.types.CollectionsObject; +import org.projectnessie.cel.types.jackson3.types.EnumWithConstantBody; import org.projectnessie.cel.types.jackson3.types.InnerType; import tools.jackson.databind.JavaType; @@ -117,6 +118,17 @@ void basics() { .isInstanceOf(IllegalArgumentException.class); } + @Test + void enumConstantSpecificClassBodyUsesDeclaringClassName() { + Jackson3Registry reg = (Jackson3Registry) newRegistry(); + reg.enumDescription(EnumWithConstantBody.class); + + assertThat(reg.findIdent(EnumWithConstantBody.class.getName() + ".SPECIAL")) + .isEqualTo(intOf(EnumWithConstantBody.SPECIAL.ordinal())); + assertThat(reg.nativeToValue(EnumWithConstantBody.SPECIAL)) + .isEqualTo(intOf(EnumWithConstantBody.SPECIAL.ordinal())); + } + @Test void types() { Jackson3Registry reg = (Jackson3Registry) newRegistry(); diff --git a/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/types/EnumWithConstantBody.java b/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/types/EnumWithConstantBody.java new file mode 100644 index 00000000..454f9d6e --- /dev/null +++ b/jackson3/src/test/java/org/projectnessie/cel/types/jackson3/types/EnumWithConstantBody.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2026 The Authors of CEL-Java + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.projectnessie.cel.types.jackson3.types; + +public enum EnumWithConstantBody { + DEFAULT, + SPECIAL { + @Override + public String label() { + return "special"; + } + }; + + public String label() { + return name(); + } +}