You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2026/07/25 16:46:06 UTC

(struts) branch WW-3871-typeconversion-key-derivation created (now a1c2193af)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git


      at a1c2193af WW-3871 test(core): cover key-prefix crossover, empty class-level key, and KeyProperty_ end-to-end binding

This branch includes the following new commits:

     new cf0cb2e22 WW-3871 docs: add design spec for @TypeConversion key derivation
     new f3952e487 WW-3871 docs: note interaction with the 7.3.0 converter mapping cache
     new a06198e4e WW-3871 docs: add implementation plan for @TypeConversion key derivation
     new 734f85982 WW-3871 feat(core): add ConversionRule#prefix() owning the rule-to-prefix table
     new 43d7e9b6b WW-3871 refactor(core): split addConverterMapping into per-source passes
     new 5c2a964a5 WW-3871 feat(core): derive conversion mapping keys through a single resolver
     new b487d6640 WW-3871 fix(core): derive class level conversion keys and stop dropping later entries
     new 217f74c75 WW-3871 feat(core): support @TypeConversion on fields
     new af603fa69 WW-3871 test(core): assert bare conversion keys bind through the action lifecycle
     new 0c86a3a1e WW-3871 docs(core): document conversion key derivation and field level support
     new f5ce53646 WW-3871 docs(core): add deprecated Collection_ prefix to parameter table
     new 955e3d9d1 WW-3871 fix(core): widen resolveKey idempotence guard against any rule prefix
     new 919bbd138 WW-3871 docs(core): correct TypeConversion Javadoc property attribute and determiner package
     new a1c2193af WW-3871 test(core): cover key-prefix crossover, empty class-level key, and KeyProperty_ end-to-end binding

The 14 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(struts) 07/14: WW-3871 fix(core): derive class level conversion keys and stop dropping later entries

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit b487d6640cef469a1cbb60385c34a5fdba9715a1
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:26:50 2026 +0200

    WW-3871 fix(core): derive class level conversion keys and stop dropping later entries
---
 .../struts2/conversion/impl/XWorkConverter.java    | 28 +++++-----
 .../conversion/impl/XWorkConverterTest.java        | 36 +++++++++++++
 .../struts2/util/BareKeyConversionAction.java      | 61 ++++++++++++++++++++++
 .../struts2/util/CollidingKeyConversionAction.java | 48 +++++++++++++++++
 ...lidingKeyConversionAction-conversion.properties | 19 +++++++
 5 files changed, 179 insertions(+), 13 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
index b3aa0e473..b0787735a 100644
--- a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
+++ b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
@@ -532,20 +532,22 @@ public class XWorkConverter extends DefaultTypeConverter {
      */
     private void processClassLevelAnnotations(Map<String, Object> mapping, Class clazz) {
         for (Annotation annotation : clazz.getAnnotations()) {
-            if (annotation instanceof Conversion conversion) {
-                for (TypeConversion tc : conversion.conversions()) {
-                    if (mapping.containsKey(tc.key())) {
-                        break;
-                    }
-                    if (LOG.isDebugEnabled()) {
-                        if (StringUtils.isEmpty(tc.key())) {
-                            LOG.debug("WARNING! key of @TypeConversion [{}/{}] applied to [{}] is empty!", tc.converter(), tc.converterClass(), clazz.getName());
-                        } else {
-                            LOG.debug("TypeConversion [{}/{}] with key: [{}]", tc.converter(), tc.converterClass(), tc.key());
-                        }
-                    }
-                    annotationProcessor.process(mapping, tc, tc.key());
+            if (!(annotation instanceof Conversion conversion)) {
+                continue;
+            }
+            for (TypeConversion tc : conversion.conversions()) {
+                String key = resolveKey(tc.type(), tc.rule(), tc.key());
+                if (key == null) {
+                    LOG.warn("Ignoring @TypeConversion [{}/{}] declared on [{}]: no key was given and a class level annotation has no property name to derive one from",
+                            tc.converter(), tc.converterClass(), clazz.getName());
+                    continue;
                 }
+                if (mapping.containsKey(key)) {
+                    continue;
+                }
+                LOG.debug("TypeConversion [{}/{}] declared on [{}] resolved to key [{}]",
+                        tc.converter(), tc.converterClass(), clazz.getName(), key);
+                annotationProcessor.process(mapping, tc, key);
             }
         }
     }
diff --git a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
index 5b3fea454..b791fc941 100644
--- a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
+++ b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
@@ -41,7 +41,11 @@ import org.apache.struts2.conversion.TypeConverter;
 import org.apache.struts2.conversion.StrutsTypeConverterHolder;
 import org.apache.struts2.conversion.annotations.ConversionRule;
 import org.apache.struts2.conversion.annotations.ConversionType;
+import org.apache.struts2.util.BareKeyConversionAction;
+import org.apache.struts2.util.CollidingKeyConversionAction;
 import org.apache.struts2.util.ExplicitKeyConversionAction;
+import org.apache.struts2.util.MyBean;
+import org.apache.struts2.util.MyBeanAction;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -860,6 +864,38 @@ public class XWorkConverterTest extends XWorkTestCase {
         assertNull(freshConverter.getConverter(ExplicitKeyConversionAction.class, "bareList"));
     }
 
+    public void testClassLevelBareKeysGetTheRulePrefix() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals("id", freshConverter.getConverter(BareKeyConversionAction.class, "KeyProperty_annotatedBeanMap"));
+        assertEquals(MyBean.class, freshConverter.getConverter(BareKeyConversionAction.class, "Element_annotatedBeanMap"));
+        assertEquals("id", freshConverter.getConverter(BareKeyConversionAction.class, "KeyProperty_annotatedBeanList"));
+        assertEquals(MyBean.class, freshConverter.getConverter(BareKeyConversionAction.class, "Element_annotatedBeanList"));
+    }
+
+    public void testClassLevelBareKeysMatchTheSpelledOutForm() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        for (String key : new String[]{"KeyProperty_annotatedBeanMap", "Element_annotatedBeanMap",
+                "KeyProperty_annotatedBeanList", "Element_annotatedBeanList"}) {
+            assertEquals("mismatch for " + key,
+                    freshConverter.getConverter(MyBeanAction.class, key),
+                    freshConverter.getConverter(BareKeyConversionAction.class, key));
+        }
+    }
+
+    public void testClassLevelEntriesAfterAKeyCollisionAreStillRegistered() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        // supplied by the -conversion.properties file, so the annotation must not overwrite it
+        assertEquals("true", freshConverter.getConverter(CollidingKeyConversionAction.class, "CreateIfNull_fromProperties"));
+        // the entry after the collision used to be dropped by `break`
+        assertEquals("true", freshConverter.getConverter(CollidingKeyConversionAction.class, "CreateIfNull_afterTheCollision"));
+    }
+
     public static class CountingXWorkConverter extends XWorkConverter {
         final AtomicInteger builds = new AtomicInteger();
 
diff --git a/core/src/test/java/org/apache/struts2/util/BareKeyConversionAction.java b/core/src/test/java/org/apache/struts2/util/BareKeyConversionAction.java
new file mode 100644
index 000000000..de8e3152c
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/util/BareKeyConversionAction.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The class level counterpart of {@link MyBeanAction}, declaring the same four conversions with
+ * bare property names instead of spelled-out prefixes.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.ELEMENT, converterClass = MyBean.class),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.ELEMENT, converterClass = MyBean.class)
+        })
+public class BareKeyConversionAction {
+
+    private Map annotatedBeanMap = new HashMap();
+    private List annotatedBeanList = new ArrayList();
+
+    public Map getAnnotatedBeanMap() {
+        return annotatedBeanMap;
+    }
+
+    public void setAnnotatedBeanMap(Map annotatedBeanMap) {
+        this.annotatedBeanMap = annotatedBeanMap;
+    }
+
+    public List getAnnotatedBeanList() {
+        return annotatedBeanList;
+    }
+
+    public void setAnnotatedBeanList(List annotatedBeanList) {
+        this.annotatedBeanList = annotatedBeanList;
+    }
+}
diff --git a/core/src/test/java/org/apache/struts2/util/CollidingKeyConversionAction.java b/core/src/test/java/org/apache/struts2/util/CollidingKeyConversionAction.java
new file mode 100644
index 000000000..e8d30f91d
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/util/CollidingKeyConversionAction.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The first conversion entry collides with a key already supplied by
+ * {@code CollidingKeyConversionAction-conversion.properties}; the second must still be registered.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(key = "fromProperties", rule = ConversionRule.CREATE_IF_NULL, value = "false"),
+                @TypeConversion(key = "afterTheCollision", rule = ConversionRule.CREATE_IF_NULL, value = "true")
+        })
+public class CollidingKeyConversionAction {
+
+    private List afterTheCollision = new ArrayList();
+
+    public List getAfterTheCollision() {
+        return afterTheCollision;
+    }
+
+    public void setAfterTheCollision(List afterTheCollision) {
+        this.afterTheCollision = afterTheCollision;
+    }
+}
diff --git a/core/src/test/resources/org/apache/struts2/util/CollidingKeyConversionAction-conversion.properties b/core/src/test/resources/org/apache/struts2/util/CollidingKeyConversionAction-conversion.properties
new file mode 100644
index 000000000..f03453294
--- /dev/null
+++ b/core/src/test/resources/org/apache/struts2/util/CollidingKeyConversionAction-conversion.properties
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+CreateIfNull_fromProperties=true


(struts) 01/14: WW-3871 docs: add design spec for @TypeConversion key derivation

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit cf0cb2e224dde8af92ad3865551192e591a33a18
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 13:49:07 2026 +0200

    WW-3871 docs: add design spec for @TypeConversion key derivation
    
    Specifies deriving the ConversionRule prefix for @TypeConversion keys at
    class, method and field level via a single resolver, adds ElementType.FIELD
    as a target, and records the break/continue and empty-key fixes in the same
    code block.
    
    Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
---
 ...WW-3871-typeconversion-key-derivation-design.md | 188 +++++++++++++++++++++
 1 file changed, 188 insertions(+)

diff --git a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
new file mode 100644
index 000000000..340968138
--- /dev/null
+++ b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
@@ -0,0 +1,188 @@
+# WW-3871 — `@TypeConversion` key derivation
+
+**Ticket:** [WW-3871](https://issues.apache.org/jira/browse/WW-3871) — TypeConversion annotation support improvement
+**Target version:** 7.3.0
+**Date:** 2026-07-25
+
+## Problem
+
+The reporter asked that `@TypeConversion` build its own key from the property name once a
+`ConversionRule` is given, instead of forcing:
+
+```java
+@TypeConversion(key = "CreateIfNull_users", rule = ConversionRule.CreateIfNull, value = "true")
+```
+
+Half of this already works. Commit `77cbafb74` (2018) taught `XWorkConverter` to derive the key for
+**method-level** annotations: with no `key`, the property name is resolved from the method and the
+rule's prefix is prepended (`XWorkConverter.java:526-545`).
+
+Three gaps remain:
+
+1. **Class-level `@Conversion(conversions = {...})` has no derivation at all.** The `key` is used
+   verbatim (`XWorkConverter.java:504-519`), so callers still spell out prefixes — see
+   `core/src/test/java/org/apache/struts2/util/MyBeanAction.java:38-41`.
+2. **`@TypeConversion` is `@Target({METHOD})`**, while its own Javadoc claims it "can be applied at
+   property and method level" (`TypeConversion.java:51`).
+3. **Explicit keys are never normalised.** `@TypeConversion(key = "foo", rule = CREATE_IF_NULL)` on a
+   setter registers `foo`, a mapping nothing reads — `DefaultObjectTypeDeterminer` looks up
+   `CreateIfNull_foo`.
+
+Two defects live in the same code block and are fixed here rather than left behind:
+
+- `break` where `continue` is meant (`XWorkConverter.java:508` and `:542`). One already-mapped key
+  aborts the **remaining** `@TypeConversion` entries in a `@Conversion` array.
+- An empty class-level `key` registers a mapping under `""`. `DefaultConversionAnnotationProcessor`
+  guards only `null` (`:58`).
+
+## Goals
+
+- A bare property name in `key` works at class, method and field level, for every `ConversionRule`.
+- Existing annotations that spell out the prefix keep working byte-for-byte.
+- `@TypeConversion` becomes usable on fields, matching its documentation.
+- The rule-to-prefix table lives in one place.
+
+## Non-goals
+
+- `ConversionRule.COLLECTION` / the `Collection_` prefix stays deprecated-as-is.
+- `ConversionRule.MAP` keeps having no prefix of its own.
+- No changes to `struts-conversion.properties` or `<Class>-conversion.properties` parsing. This
+  ticket is annotations only.
+
+## Design
+
+### 1. Rule-to-prefix mapping moves onto `ConversionRule`
+
+`org.apache.struts2.conversion.annotations.ConversionRule` gains:
+
+```java
+public String prefix() {
+    return switch (this) {
+        case COLLECTION     -> DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX; // "Collection_"
+        case CREATE_IF_NULL -> DefaultObjectTypeDeterminer.CREATE_IF_NULL_PREFIX;     // "CreateIfNull_"
+        case ELEMENT        -> DefaultObjectTypeDeterminer.ELEMENT_PREFIX;            // "Element_"
+        case KEY            -> DefaultObjectTypeDeterminer.KEY_PREFIX;                // "Key_"
+        case KEY_PROPERTY   -> DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX;       // "KeyProperty_"
+        case PROPERTY, MAP  -> "";
+    };
+}
+```
+
+`PROPERTY` and `MAP` returning `""` preserves today's behaviour: `DefaultObjectTypeDeterminer` reads
+map and collection metadata through the `Key_` and `Element_` keys, never through a `Map_` key.
+
+The `annotations` package already depends on `conversion.impl` (`TypeConversion.converterClass()`
+defaults to `XWorkBasicConverter.class`), so referencing the prefix constants adds no new coupling.
+An exhaustive `switch` over the enum means a future rule cannot silently miss a prefix.
+
+### 2. One key resolver in `XWorkConverter`
+
+```java
+static String resolveKey(TypeConversion tc, String name) {
+    if (name == null || name.isEmpty()) {
+        return null;                        // caller skips the entry and logs WARN
+    }
+    if (tc.type() == ConversionType.APPLICATION) {
+        return name;                        // key is a class name, never prefixed
+    }
+    String prefix = tc.rule().prefix();
+    return name.startsWith(prefix) ? name : prefix + name;
+}
+```
+
+All three annotation passes route both explicit keys and derived property names through this
+function, so the three call sites cannot drift apart.
+
+**The `APPLICATION` carve-out** is belt-and-braces: application-scope entries use the default
+`PROPERTY` rule in practice, where the prefix is `""` anyway. Without it,
+`@TypeConversion(type = APPLICATION, key = "java.util.Date", rule = ELEMENT)` would register
+`Element_java.util.Date` into the global converter map, which nothing reads.
+
+**`name.startsWith(prefix)`** is the backward-compatibility guarantee: an already-prefixed key is
+returned untouched, so `key = "KeyProperty_annotatedBeanMap"` and `key = "annotatedBeanMap"` both
+resolve to `KeyProperty_annotatedBeanMap` under `rule = KEY_PROPERTY`. It misfires only for a
+property literally named `KeyProperty_foo` (or another prefix), which is legal Java but effectively
+nonexistent; such a property gets exactly today's behaviour.
+
+### 3. Field-level support
+
+`@TypeConversion` becomes `@Target({ElementType.METHOD, ElementType.FIELD})`.
+
+`addConverterMapping` splits into four ordered passes, keeping today's first-writer-wins rule:
+
+```java
+protected void addConverterMapping(Map<String, Object> mapping, Class clazz) {
+    fileProcessor.process(mapping, clazz, buildConverterFilename(clazz));   // 1
+    processClassLevelAnnotations(mapping, clazz);                           // 2
+    processMethodAnnotations(mapping, clazz);                               // 3
+    processFieldAnnotations(mapping, clazz);                                // 4  new
+}
+```
+
+This yields the precedence **class > method > field**, which preserves current behaviour exactly:
+class-level `@Conversion` already outranks methods, and field annotations — none of which exist
+today — only fill gaps.
+
+Extracting the three passes into named private methods is the targeted cleanup this ticket earns.
+The current single method is roughly 45 lines of nested loops concealing the `break` defect, and a
+fourth pass would push it past readable.
+
+The field pass iterates `clazz.getDeclaredFields()` — declared, not inherited, because
+`buildConverterMapping` already walks the class hierarchy and calls `addConverterMapping` per class.
+It skips `static` and synthetic fields, which also makes the interface case a no-op
+(`getDeclaredFields()` on an interface returns its constants). A field's own name is the property
+name; no getter/setter parsing is involved.
+
+### 4. Error handling
+
+| Situation | Today | After |
+|---|---|---|
+| Class-level entry with `key = ""` | registers a `""` mapping | skipped, `WARN` naming class and annotation |
+| `@TypeConversion` on a non-property method (`execute()`) with no key | silently dropped at DEBUG | skipped, `WARN` naming class and method |
+| Field annotation whose key a method already claimed | n/a | skipped, `DEBUG` — the documented precedence, made visible |
+| Second entry in a `@Conversion` array after a key collision | **dropped** (`break`) | processed (`continue`) |
+
+The class-level `mapping.containsKey(...)` check moves **after** key resolution; it currently tests
+the raw key, which post-change would be the wrong string. `DefaultConversionAnnotationProcessor.process`
+keeps its `key == null` guard as defence in depth even though callers no longer pass null.
+
+## Testing
+
+Both affected test classes extend `XWorkTestCase`, i.e. JUnit 3 style — new tests use
+`public void testXxx()` with no `@Test` annotation, which would silently never run there.
+
+**`XWorkConverterTest` / `AnnotationXWorkConverterTest`:**
+
+- bare key + rule resolves to the prefixed key
+- already-prefixed key + same rule is unchanged (idempotence)
+- `PROPERTY` and `MAP` rules leave the key untouched
+- `type = APPLICATION` leaves the key untouched regardless of rule
+- empty key and non-property method produce no mapping entry, and specifically no `""` key
+
+**`MyBeanActionTest` — end-to-end:** `MyBeanAction` keeps its four spelled-out class-level prefixes
+untouched, which is what proves existing applications don't break. A second fixture action declares
+the same four conversions with **bare** keys; the test asserts both produce identical converter
+mappings and identical bound results.
+
+**Field support:** a fixture with `@TypeConversion` on a private field, asserting its derived key
+matches the setter form's, plus a test that a method annotation wins when both a field and its
+setter are annotated for the same key.
+
+**`continue` regression:** a fixture whose `@Conversion` array has an early entry colliding with a
+key already in the mapping, asserting the later entries still register. This regression is currently
+invisible.
+
+## Documentation
+
+- `TypeConversion` Javadoc: the parameter table's `key` row gains the derivation rule (it currently
+  says only "Defaults to the property name", which understates it); the class-level example drops its
+  now-redundant prefixes; an `@since 7.3.0` note records that bare keys are accepted at class and
+  field level, and that fields are a supported target.
+- `ConversionRule` Javadoc: document `prefix()` and which rules have none.
+
+## Compatibility
+
+Source- and binary-compatible. The only behavioural change to existing code is that an explicit
+method-level key carrying a non-`PROPERTY` rule without its prefix now resolves to the prefixed key.
+That mapping is unreachable today, so the change turns a silent no-op into the behaviour the author
+intended.


(struts) 13/14: WW-3871 docs(core): correct TypeConversion Javadoc property attribute and determiner package

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 919bbd1380476cddf6f5c9ac33376b266dd2994d
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 17:11:30 2026 +0200

    WW-3871 docs(core): correct TypeConversion Javadoc property attribute and determiner package
    
    Two pre-existing errors in the block this ticket's commits already touch:
    the APPLICATION example used a non-existent "property" attribute where
    "key" is the working form (see ConversionTestAction.java:97), and the
    rule() Javadoc pointed at org.apache.struts2.util.DefaultObjectTypeDeterminer
    instead of the actual org.apache.struts2.conversion.impl package.
---
 .../org/apache/struts2/conversion/annotations/TypeConversion.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
index e4f86b965..efd6b77c6 100644
--- a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
+++ b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
@@ -145,7 +145,7 @@ import java.lang.annotation.Target;
  *       this.keyValues = keyValues;
  *   }
  *
- *   &#64;TypeConversion(type = ConversionType.APPLICATION, property = "java.util.Date", converterClass = XWorkBasicConverter.class)
+ *   &#64;TypeConversion(type = ConversionType.APPLICATION, key = "java.util.Date", converterClass = XWorkBasicConverter.class)
  *   public String execute() throws Exception {
  *       return SUCCESS;
  *   }
@@ -185,7 +185,7 @@ public @interface TypeConversion {
 
     /**
      * The ConversionRule can be a PROPERTY, KEY, KEY_PROPERTY, ELEMENT, COLLECTION (deprecated) or a MAP.
-     * Note: Collection and Map conversion rules can be determined via org.apache.struts2.util.DefaultObjectTypeDeterminer.
+     * Note: Collection and Map conversion rules can be determined via org.apache.struts2.conversion.impl.DefaultObjectTypeDeterminer.
      *
      * @see DefaultObjectTypeDeterminer
      *


(struts) 04/14: WW-3871 feat(core): add ConversionRule#prefix() owning the rule-to-prefix table

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 734f85982359d5b4dff0a9d7414a0cc3f38ed130
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:09:41 2026 +0200

    WW-3871 feat(core): add ConversionRule#prefix() owning the rule-to-prefix table
---
 .../conversion/annotations/ConversionRule.java     | 21 ++++++++++++++++++
 .../annotations/ConversionRuleTest.java}           | 25 +++++++++++-----------
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java b/core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java
index fa75f69e4..090a6709a 100644
--- a/core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java
+++ b/core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java
@@ -18,6 +18,8 @@
  */
 package org.apache.struts2.conversion.annotations;
 
+import org.apache.struts2.conversion.impl.DefaultObjectTypeDeterminer;
+
 /**
  * <code>ConversionRule</code>
  *
@@ -28,6 +30,25 @@ public enum ConversionRule {
 
     PROPERTY, COLLECTION, MAP, KEY, KEY_PROPERTY, ELEMENT, CREATE_IF_NULL;
 
+    /**
+     * The prefix a conversion mapping key carries for this rule, as read back by
+     * {@link DefaultObjectTypeDeterminer}. {@code PROPERTY} and {@code MAP} have no prefix of their
+     * own: map and collection metadata is read through the {@code Key_} and {@code Element_} keys.
+     *
+     * @return the mapping key prefix, never null; an empty string when the rule has none
+     * @since 7.3.0
+     */
+    public String prefix() {
+        return switch (this) {
+            case COLLECTION -> DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX;
+            case CREATE_IF_NULL -> DefaultObjectTypeDeterminer.CREATE_IF_NULL_PREFIX;
+            case ELEMENT -> DefaultObjectTypeDeterminer.ELEMENT_PREFIX;
+            case KEY -> DefaultObjectTypeDeterminer.KEY_PREFIX;
+            case KEY_PROPERTY -> DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX;
+            case PROPERTY, MAP -> "";
+        };
+    }
+
     @Override
     public String toString() {
         return super.toString().toUpperCase();
diff --git a/core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java b/core/src/test/java/org/apache/struts2/conversion/annotations/ConversionRuleTest.java
similarity index 58%
copy from core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java
copy to core/src/test/java/org/apache/struts2/conversion/annotations/ConversionRuleTest.java
index fa75f69e4..04e63e1ec 100644
--- a/core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java
+++ b/core/src/test/java/org/apache/struts2/conversion/annotations/ConversionRuleTest.java
@@ -18,19 +18,20 @@
  */
 package org.apache.struts2.conversion.annotations;
 
-/**
- * <code>ConversionRule</code>
- *
- * @author Rainer Hermanns
- * @version $Id$
- */
-public enum ConversionRule {
+import org.junit.Test;
 
-    PROPERTY, COLLECTION, MAP, KEY, KEY_PROPERTY, ELEMENT, CREATE_IF_NULL;
+import static org.junit.Assert.assertEquals;
 
-    @Override
-    public String toString() {
-        return super.toString().toUpperCase();
+public class ConversionRuleTest {
+
+    @Test
+    public void prefixIsDefinedForEveryRule() {
+        assertEquals("", ConversionRule.PROPERTY.prefix());
+        assertEquals("", ConversionRule.MAP.prefix());
+        assertEquals("Collection_", ConversionRule.COLLECTION.prefix());
+        assertEquals("CreateIfNull_", ConversionRule.CREATE_IF_NULL.prefix());
+        assertEquals("Element_", ConversionRule.ELEMENT.prefix());
+        assertEquals("Key_", ConversionRule.KEY.prefix());
+        assertEquals("KeyProperty_", ConversionRule.KEY_PROPERTY.prefix());
     }
 }
-


(struts) 05/14: WW-3871 refactor(core): split addConverterMapping into per-source passes

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 43d7e9b6b37a012846bcc52a3ce42a2651564cd5
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:13:20 2026 +0200

    WW-3871 refactor(core): split addConverterMapping into per-source passes
---
 .../struts2/conversion/impl/XWorkConverter.java     | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
index 5579a15d3..8685e9d71 100644
--- a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
+++ b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
@@ -498,10 +498,16 @@ public class XWorkConverter extends DefaultTypeConverter {
         String converterFilename = buildConverterFilename(clazz);
         fileProcessor.process(mapping, clazz, converterFilename);
 
-        // Process annotations
-        Annotation[] annotations = clazz.getAnnotations();
+        processClassLevelAnnotations(mapping, clazz);
+        processMethodAnnotations(mapping, clazz);
+    }
 
-        for (Annotation annotation : annotations) {
+    /**
+     * Registers the {@link TypeConversion} entries declared by a class level {@link Conversion}
+     * annotation.
+     */
+    private void processClassLevelAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Annotation annotation : clazz.getAnnotations()) {
             if (annotation instanceof Conversion conversion) {
                 for (TypeConversion tc : conversion.conversions()) {
                     if (mapping.containsKey(tc.key())) {
@@ -518,11 +524,14 @@ public class XWorkConverter extends DefaultTypeConverter {
                 }
             }
         }
+    }
 
-        // Process annotated methods
+    /**
+     * Registers {@link TypeConversion} annotations found on the class' methods.
+     */
+    private void processMethodAnnotations(Map<String, Object> mapping, Class clazz) {
         for (Method method : clazz.getMethods()) {
-            annotations = method.getAnnotations();
-            for (Annotation annotation : annotations) {
+            for (Annotation annotation : method.getAnnotations()) {
                 if (annotation instanceof TypeConversion tc) {
                     String key = tc.key();
                     // Default to the property name with prefix


(struts) 14/14: WW-3871 test(core): cover key-prefix crossover, empty class-level key, and KeyProperty_ end-to-end binding

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit a1c2193af4f6f636289ce8e62bcd36257e6cea06
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 17:11:36 2026 +0200

    WW-3871 test(core): cover key-prefix crossover, empty class-level key, and KeyProperty_ end-to-end binding
    
    - testResolveKeyLeavesAnAlreadyPrefixedKeyAlone: add the COLLECTION/ELEMENT
      crossover cases that demonstrate the resolveKey guard fix (fail before,
      pass after).
    - New EmptyKeyConversionAction fixture plus
      testClassLevelEmptyKeyRegistersNoMapping: a class-level @TypeConversion
      with no key must be skipped, not registered under "". This was the one
      behavioural bullet in the spec's test plan with no coverage.
    - MyBeanActionTest.testBareConversionKeysBindTheSameWayAsPrefixedOnes: add
      an assertion that the bare KeyProperty_ derivation actually binds the
      list index onto the created bean's id property end to end, not just that
      a converter mapping exists.
---
 .../conversion/impl/XWorkConverterTest.java        | 19 ++++++++++++
 .../struts2/util/EmptyKeyConversionAction.java     | 34 ++++++++++++++++++++++
 .../org/apache/struts2/util/MyBeanActionTest.java  |  3 ++
 3 files changed, 56 insertions(+)

diff --git a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
index 1ca4bc161..db16433b1 100644
--- a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
+++ b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
@@ -43,6 +43,7 @@ import org.apache.struts2.conversion.annotations.ConversionRule;
 import org.apache.struts2.conversion.annotations.ConversionType;
 import org.apache.struts2.util.BareKeyConversionAction;
 import org.apache.struts2.util.CollidingKeyConversionAction;
+import org.apache.struts2.util.EmptyKeyConversionAction;
 import org.apache.struts2.util.ExplicitKeyConversionAction;
 import org.apache.struts2.util.FieldConversionAction;
 import org.apache.struts2.util.MyBean;
@@ -836,6 +837,14 @@ public class XWorkConverterTest extends XWorkTestCase {
                 XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY_PROPERTY, "KeyProperty_annotatedBeanMap"));
         assertEquals("Key_beanMap",
                 XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY, "Key_beanMap"));
+
+        // COLLECTION and ELEMENT are interchangeable in DefaultConversionAnnotationProcessor and
+        // DefaultObjectTypeDeterminer, so a key already carrying either prefix must be left alone
+        // regardless of which of the two rules is declared.
+        assertEquals("Element_users",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.COLLECTION, "Element_users"));
+        assertEquals("Collection_users",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.ELEMENT, "Collection_users"));
     }
 
     public void testResolveKeyDoesNotPrefixPropertyOrMapRules() {
@@ -897,6 +906,16 @@ public class XWorkConverterTest extends XWorkTestCase {
         assertEquals("true", freshConverter.getConverter(CollidingKeyConversionAction.class, "CreateIfNull_afterTheCollision"));
     }
 
+    public void testClassLevelEmptyKeyRegistersNoMapping() throws Exception {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        Map<String, Object> mapping = freshConverter.buildConverterMapping(EmptyKeyConversionAction.class);
+
+        assertFalse("an empty class-level key must not register a \"\" mapping", mapping.containsKey(""));
+        assertTrue("no mapping should have been registered at all", mapping.isEmpty());
+    }
+
     public void testFieldLevelAnnotationDerivesKeyFromTheFieldName() {
         XWorkConverter freshConverter = container.inject(XWorkConverter.class);
         freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
diff --git a/core/src/test/java/org/apache/struts2/util/EmptyKeyConversionAction.java b/core/src/test/java/org/apache/struts2/util/EmptyKeyConversionAction.java
new file mode 100644
index 000000000..267df549b
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/util/EmptyKeyConversionAction.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+/**
+ * A class level {@link TypeConversion} has no property name to derive a key from, so an unset
+ * (empty) {@code key} must be skipped rather than registered under {@code ""}.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+        })
+public class EmptyKeyConversionAction {
+}
diff --git a/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java b/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java
index 3f19efbfe..bd9d1da44 100644
--- a/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java
+++ b/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java
@@ -143,6 +143,9 @@ public class MyBeanActionTest extends XWorkTestCase {
         assertEquals(MyBean.class, action.getAnnotatedBeanList().get(0).getClass());
         assertEquals("This is the bla bean by annotation",
                 proxy.getInvocation().getStack().findValue("annotatedBeanList.get(0).name"));
+        // KeyProperty_annotatedBeanList (value = "id"): the index used to address the list,
+        // 1234567890, is bound onto the created bean's own "id" property.
+        assertEquals(Long.valueOf(1234567890L), ((MyBean) action.getAnnotatedBeanList().get(0)).getId());
 
         // Key_annotatedBeanMap makes the key a Long, Element_annotatedBeanMap makes the value a MyBean
         assertTrue(action.getAnnotatedBeanMap().containsKey(1234567891L));


(struts) 10/14: WW-3871 docs(core): document conversion key derivation and field level support

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 0c86a3a1e0b28e413a389853cd1c053baf8c19de
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:45:29 2026 +0200

    WW-3871 docs(core): document conversion key derivation and field level support
---
 .../conversion/annotations/TypeConversion.java      | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
index 749d715c9..c65b5d08e 100644
--- a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
+++ b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
@@ -48,7 +48,7 @@ import java.lang.annotation.Target;
  * <p><u>Annotation usage:</u></p>
  *
  * <!-- START SNIPPET: usage -->
- * <p>The TypeConversion annotation can be applied at property and method level.</p>
+ * <p>The TypeConversion annotation can be applied at field and method level.</p>
  * <!-- END SNIPPET: usage -->
  *
  * <p><u>Annotation parameters:</u></p>
@@ -67,8 +67,11 @@ import java.lang.annotation.Target;
  * <tr>
  * <td>key</td>
  * <td>no</td>
- * <td>The annotated property/key name</td>
- * <td>The optional property name mostly used within TYPE level annotations.</td>
+ * <td>The annotated property/field name</td>
+ * <td>The property name the rule applies to. The matching prefix for the given rule
+ * (<code>Key_</code>, <code>Element_</code>, <code>KeyProperty_</code>, <code>CreateIfNull_</code>)
+ * is prepended automatically unless the key already carries it. Required on TYPE level annotations,
+ * where there is no member name to derive it from.</td>
  * </tr>
  * <tr>
  * <td>type</td>
@@ -129,6 +132,9 @@ import java.lang.annotation.Target;
  *       this.convertDouble = convertDouble;
  *   }
  *
+ *   &#64;TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+ *   private List users = null;
+ *
  *   &#64;TypeConversion(rule = ConversionRule.COLLECTION, converterClass = String.class)
  *   public void setUsers( List users ) {
  *       this.users = users;
@@ -155,10 +161,15 @@ import java.lang.annotation.Target;
 public @interface TypeConversion {
 
     /**
-     * The optional key name used within TYPE level annotations.
-     * Defaults to the property name.
+     * The property name this conversion applies to. Optional on fields and methods, where it
+     * defaults to the property name; required on TYPE level annotations.
+     *
+     * <p>The prefix matching the declared {@link ConversionRule} is prepended automatically, so
+     * {@code @TypeConversion(key = "users", rule = ConversionRule.CREATE_IF_NULL, value = "true")}
+     * and {@code @TypeConversion(key = "CreateIfNull_users", ...)} are equivalent.</p>
      *
      * @return key
+     * @since 7.3.0 the rule prefix is derived; previously the full key had to be spelled out
      */
     String key() default "";
 


(struts) 06/14: WW-3871 feat(core): derive conversion mapping keys through a single resolver

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 5c2a964a5c5f7ade95a9609d155d62ccab7747bf
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:20:12 2026 +0200

    WW-3871 feat(core): derive conversion mapping keys through a single resolver
---
 .../struts2/conversion/impl/XWorkConverter.java    | 58 +++++++++++++++-------
 .../conversion/impl/XWorkConverterTest.java        | 46 +++++++++++++++++
 .../struts2/util/ExplicitKeyConversionAction.java  | 43 ++++++++++++++++
 3 files changed, 128 insertions(+), 19 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
index 8685e9d71..b3aa0e473 100644
--- a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
+++ b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
@@ -27,6 +27,8 @@ import org.apache.struts2.conversion.ConversionFileProcessor;
 import org.apache.struts2.conversion.TypeConverter;
 import org.apache.struts2.conversion.TypeConverterHolder;
 import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.ConversionType;
 import org.apache.struts2.conversion.annotations.TypeConversion;
 import org.apache.struts2.inject.Inject;
 import org.apache.struts2.util.AnnotationUtils;
@@ -486,6 +488,28 @@ public class XWorkConverter extends DefaultTypeConverter {
         return (lastClass != null && lastProperty != null) ? new Object[] {lastClass, lastProperty} : null;
     }
 
+    /**
+     * Resolves the conversion mapping key for an annotation: the given name carrying the
+     * {@link ConversionRule}'s prefix. A name that already starts with that prefix is returned
+     * unchanged, so annotations that spell the prefix out keep working.
+     *
+     * @param type the annotation's {@link ConversionType}; APPLICATION keys are class names and are never prefixed
+     * @param rule the annotation's {@link ConversionRule}
+     * @param name an explicit key or a property name derived from a method or field
+     * @return the mapping key, or null when no name is available and the entry must be skipped
+     * @since 7.3.0
+     */
+    static String resolveKey(ConversionType type, ConversionRule rule, String name) {
+        if (StringUtils.isEmpty(name)) {
+            return null;
+        }
+        if (type == ConversionType.APPLICATION) {
+            return name;
+        }
+        String prefix = rule.prefix();
+        return name.startsWith(prefix) ? name : prefix + name;
+    }
+
     /**
      * Looks for converter mappings for the specified class and adds it to an existing map.  Only new converters are
      * added.  If a converter is defined on a key that already exists, the converter is ignored.
@@ -532,26 +556,22 @@ public class XWorkConverter extends DefaultTypeConverter {
     private void processMethodAnnotations(Map<String, Object> mapping, Class clazz) {
         for (Method method : clazz.getMethods()) {
             for (Annotation annotation : method.getAnnotations()) {
-                if (annotation instanceof TypeConversion tc) {
-                    String key = tc.key();
-                    // Default to the property name with prefix
-                    if (StringUtils.isEmpty(key)) {
-                        key = AnnotationUtils.resolvePropertyName(method);
-                        key = switch (tc.rule()) {
-                            case COLLECTION -> DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX + key;
-                            case CREATE_IF_NULL -> DefaultObjectTypeDeterminer.CREATE_IF_NULL_PREFIX + key;
-                            case ELEMENT -> DefaultObjectTypeDeterminer.ELEMENT_PREFIX + key;
-                            case KEY -> DefaultObjectTypeDeterminer.KEY_PREFIX + key;
-                            case KEY_PROPERTY -> DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX + key;
-                            default -> key;
-                        };
-                        LOG.debug("Retrieved key [{}] from method name [{}]", key, method.getName());
-                    }
-                    if (mapping.containsKey(key)) {
-                        break;
-                    }
-                    annotationProcessor.process(mapping, tc, key);
+                if (!(annotation instanceof TypeConversion tc)) {
+                    continue;
+                }
+                String name = StringUtils.isEmpty(tc.key()) ? AnnotationUtils.resolvePropertyName(method) : tc.key();
+                String key = resolveKey(tc.type(), tc.rule(), name);
+                if (key == null) {
+                    LOG.warn("Ignoring @TypeConversion on [{}#{}]: no key was given and no property name could be derived from the method",
+                            clazz.getName(), method.getName());
+                    continue;
+                }
+                if (mapping.containsKey(key)) {
+                    continue;
                 }
+                LOG.debug("TypeConversion [{}/{}] on method [{}] resolved to key [{}]",
+                        tc.converter(), tc.converterClass(), method.getName(), key);
+                annotationProcessor.process(mapping, tc, key);
             }
         }
     }
diff --git a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
index 9be7c8c48..5b3fea454 100644
--- a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
+++ b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
@@ -39,6 +39,9 @@ import org.apache.struts2.util.reflection.ReflectionContextState;
 import ognl.OgnlRuntime;
 import org.apache.struts2.conversion.TypeConverter;
 import org.apache.struts2.conversion.StrutsTypeConverterHolder;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.ConversionType;
+import org.apache.struts2.util.ExplicitKeyConversionAction;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -814,6 +817,49 @@ public class XWorkConverterTest extends XWorkTestCase {
         assertEquals(converted, Arrays.asList(1, 2, 3));
     }
 
+    public void testResolveKeyPrependsTheRulePrefix() {
+        assertEquals("KeyProperty_annotatedBeanMap",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY_PROPERTY, "annotatedBeanMap"));
+        assertEquals("Element_annotatedBeanList",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.ELEMENT, "annotatedBeanList"));
+        assertEquals("CreateIfNull_users",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.CREATE_IF_NULL, "users"));
+    }
+
+    public void testResolveKeyLeavesAnAlreadyPrefixedKeyAlone() {
+        assertEquals("KeyProperty_annotatedBeanMap",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY_PROPERTY, "KeyProperty_annotatedBeanMap"));
+        assertEquals("Key_beanMap",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY, "Key_beanMap"));
+    }
+
+    public void testResolveKeyDoesNotPrefixPropertyOrMapRules() {
+        assertEquals("someProperty",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.PROPERTY, "someProperty"));
+        assertEquals("keyValues",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.MAP, "keyValues"));
+    }
+
+    public void testResolveKeyNeverPrefixesApplicationScopedKeys() {
+        assertEquals("java.util.Date",
+                XWorkConverter.resolveKey(ConversionType.APPLICATION, ConversionRule.PROPERTY, "java.util.Date"));
+        assertEquals("java.util.Date",
+                XWorkConverter.resolveKey(ConversionType.APPLICATION, ConversionRule.ELEMENT, "java.util.Date"));
+    }
+
+    public void testResolveKeyReturnsNullWhenNoNameIsAvailable() {
+        assertNull(XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.PROPERTY, null));
+        assertNull(XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY, ""));
+    }
+
+    public void testExplicitMethodKeyGetsTheRulePrefix() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals("true", freshConverter.getConverter(ExplicitKeyConversionAction.class, "CreateIfNull_bareList"));
+        assertNull(freshConverter.getConverter(ExplicitKeyConversionAction.class, "bareList"));
+    }
+
     public static class CountingXWorkConverter extends XWorkConverter {
         final AtomicInteger builds = new AtomicInteger();
 
diff --git a/core/src/test/java/org/apache/struts2/util/ExplicitKeyConversionAction.java b/core/src/test/java/org/apache/struts2/util/ExplicitKeyConversionAction.java
new file mode 100644
index 000000000..8997d0696
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/util/ExplicitKeyConversionAction.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Declares a method level {@link TypeConversion} with an explicit, unprefixed key. Before WW-3871
+ * this registered a bare {@code bareList} mapping that nothing ever read.
+ */
+public class ExplicitKeyConversionAction {
+
+    private List bareList = new ArrayList();
+
+    public List getBareList() {
+        return bareList;
+    }
+
+    @TypeConversion(key = "bareList", rule = ConversionRule.CREATE_IF_NULL, value = "true")
+    public void setBareList(List bareList) {
+        this.bareList = bareList;
+    }
+}


(struts) 12/14: WW-3871 fix(core): widen resolveKey idempotence guard against any rule prefix

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 955e3d9d10653ec3f8062160c6a7b9142d764809
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 17:11:25 2026 +0200

    WW-3871 fix(core): widen resolveKey idempotence guard against any rule prefix
    
    resolveKey only recognized a key as already-prefixed if it started with
    its own declared rule's prefix. COLLECTION and ELEMENT are interchangeable
    throughout the conversion pipeline (DefaultConversionAnnotationProcessor
    handles them in the same branch, DefaultObjectTypeDeterminer.getElementClass
    reads Element_ then falls back to the deprecated Collection_), so
    key="Element_users" with rule=COLLECTION silently doubled to
    Collection_Element_users instead of being left alone, losing the mapping.
    Match against every known rule's prefix instead.
    
    Also documents two related precedence subtleties surfaced during review:
    processFieldAnnotations' Javadoc now notes that an inherited method can
    claim a key before a subclass's own field annotation is considered, since
    getMethods() includes inherited methods and runs first; and the
    unresolvable-key WARN in processMethodAnnotations now names the method's
    declaring class rather than the class being scanned, since getMethods()
    can surface the same inherited method at every level of the hierarchy.
    
    Design spec section 2 updated to match the implementation.
---
 .../struts2/conversion/impl/XWorkConverter.java    | 30 +++++++++++++++++++---
 ...WW-3871-typeconversion-key-derivation-design.md | 26 ++++++++++++++-----
 2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
index 0dcd4fcaf..d85689d3f 100644
--- a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
+++ b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
@@ -492,8 +492,12 @@ public class XWorkConverter extends DefaultTypeConverter {
 
     /**
      * Resolves the conversion mapping key for an annotation: the given name carrying the
-     * {@link ConversionRule}'s prefix. A name that already starts with that prefix is returned
-     * unchanged, so annotations that spell the prefix out keep working.
+     * {@link ConversionRule}'s prefix. A name that already starts with <em>any</em> known rule's
+     * prefix is returned unchanged, not only the prefix of the declared rule, so annotations that
+     * spell the prefix out keep working. This matters because {@link ConversionRule#COLLECTION} and
+     * {@link ConversionRule#ELEMENT} are interchangeable in both {@link DefaultConversionAnnotationProcessor}
+     * and {@link DefaultObjectTypeDeterminer}: a key such as {@code Element_users} declared with
+     * {@code rule = COLLECTION} must not become {@code Collection_Element_users}.
      *
      * @param type the annotation's {@link ConversionType}; APPLICATION keys are class names and are never prefixed
      * @param rule the annotation's {@link ConversionRule}
@@ -509,7 +513,16 @@ public class XWorkConverter extends DefaultTypeConverter {
             return name;
         }
         String prefix = rule.prefix();
-        return name.startsWith(prefix) ? name : prefix + name;
+        if (name.startsWith(prefix)) {
+            return name;
+        }
+        for (ConversionRule other : ConversionRule.values()) {
+            String otherPrefix = other.prefix();
+            if (!otherPrefix.isEmpty() && name.startsWith(otherPrefix)) {
+                return name;   // already carries a rule prefix; leave it exactly as written
+            }
+        }
+        return prefix + name;
     }
 
     /**
@@ -567,8 +580,11 @@ public class XWorkConverter extends DefaultTypeConverter {
                 String name = StringUtils.isEmpty(tc.key()) ? AnnotationUtils.resolvePropertyName(method) : tc.key();
                 String key = resolveKey(tc.type(), tc.rule(), name);
                 if (key == null) {
+                    // method.getDeclaringClass(), not clazz: getMethods() returns inherited methods too,
+                    // so an annotation on one superclass method can otherwise log once per subclass in
+                    // the hierarchy, each naming a different, misleading class.
                     LOG.warn("Ignoring @TypeConversion on [{}#{}]: no key was given and no property name could be derived from the method",
-                            clazz.getName(), method.getName());
+                            method.getDeclaringClass().getName(), method.getName());
                     continue;
                 }
                 if (mapping.containsKey(key)) {
@@ -586,6 +602,12 @@ public class XWorkConverter extends DefaultTypeConverter {
      * fields are read: {@link #buildConverterMapping(Class)} already walks the class hierarchy and
      * calls this method once per class. Static and synthetic fields are skipped, which also makes
      * this a no-op for interfaces.
+     *
+     * <p>The stated precedence "class &gt; method &gt; field" is per-class, not per-hierarchy-level:
+     * {@link #processMethodAnnotations(Map, Class)} sees {@link Class#getMethods()}, which includes
+     * inherited public methods, so a superclass's annotated setter claims its key before this pass
+     * ever looks at a subclass's field for that same class. A subclass field annotation only wins
+     * when no method anywhere in the hierarchy already claimed its key.</p>
      */
     private void processFieldAnnotations(Map<String, Object> mapping, Class clazz) {
         for (Field field : clazz.getDeclaredFields()) {
diff --git a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
index 150d861a4..30b301c24 100644
--- a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
+++ b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
@@ -86,7 +86,16 @@ static String resolveKey(ConversionType type, ConversionRule rule, String name)
         return name;                        // key is a class name, never prefixed
     }
     String prefix = rule.prefix();
-    return name.startsWith(prefix) ? name : prefix + name;
+    if (name.startsWith(prefix)) {
+        return name;
+    }
+    for (ConversionRule other : ConversionRule.values()) {
+        String otherPrefix = other.prefix();
+        if (!otherPrefix.isEmpty() && name.startsWith(otherPrefix)) {
+            return name;   // already carries a rule prefix; leave it exactly as written
+        }
+    }
+    return prefix + name;
 }
 ```
 
@@ -101,11 +110,16 @@ function, so the three call sites cannot drift apart.
 `@TypeConversion(type = APPLICATION, key = "java.util.Date", rule = ELEMENT)` would register
 `Element_java.util.Date` into the global converter map, which nothing reads.
 
-**`name.startsWith(prefix)`** is the backward-compatibility guarantee: an already-prefixed key is
-returned untouched, so `key = "KeyProperty_annotatedBeanMap"` and `key = "annotatedBeanMap"` both
-resolve to `KeyProperty_annotatedBeanMap` under `rule = KEY_PROPERTY`. It misfires only for a
-property literally named `KeyProperty_foo` (or another prefix), which is legal Java but effectively
-nonexistent; such a property gets exactly today's behaviour.
+**The "already prefixed" guard checks every rule's prefix, not just the declared rule's.** An
+already-prefixed key is returned untouched, so `key = "KeyProperty_annotatedBeanMap"` and
+`key = "annotatedBeanMap"` both resolve to `KeyProperty_annotatedBeanMap` under `rule = KEY_PROPERTY`.
+Checking only the declared rule's prefix is not enough: `COLLECTION` and `ELEMENT` are interchangeable
+in both `DefaultConversionAnnotationProcessor` (same branch handles both) and
+`DefaultObjectTypeDeterminer.getElementClass` (reads `Element_<prop>`, falls back to the deprecated
+`Collection_<prop>`), so `key = "Element_users", rule = COLLECTION` must not become
+`Collection_Element_users`. Matching against every rule's prefix keeps that crossover working. It
+misfires only for a property literally named `KeyProperty_foo` (or another prefix), which is legal
+Java but effectively nonexistent; such a property gets exactly today's behaviour.
 
 ### 3. Field-level support
 


(struts) 08/14: WW-3871 feat(core): support @TypeConversion on fields

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 217f74c75f378b8b0fb3d508d0715d8b1bfd5122
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:34:28 2026 +0200

    WW-3871 feat(core): support @TypeConversion on fields
---
 .../conversion/annotations/TypeConversion.java     |  2 +-
 .../struts2/conversion/impl/XWorkConverter.java    | 38 ++++++++++++++
 .../conversion/impl/XWorkConverterTest.java        | 15 ++++++
 .../apache/struts2/util/FieldConversionAction.java | 58 ++++++++++++++++++++++
 4 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
index a28d8c987..749d715c9 100644
--- a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
+++ b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
@@ -150,7 +150,7 @@ import java.lang.annotation.Target;
  * @author Rainer Hermanns
  * @version $Id$
  */
-@Target({ ElementType.METHOD})
+@Target({ElementType.METHOD, ElementType.FIELD})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface TypeConversion {
 
diff --git a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
index b0787735a..0dcd4fcaf 100644
--- a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
+++ b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
@@ -42,8 +42,10 @@ import org.apache.logging.log4j.Logger;
 import org.apache.struts2.StrutsConstants;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.net.URL;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -524,6 +526,7 @@ public class XWorkConverter extends DefaultTypeConverter {
 
         processClassLevelAnnotations(mapping, clazz);
         processMethodAnnotations(mapping, clazz);
+        processFieldAnnotations(mapping, clazz);
     }
 
     /**
@@ -578,6 +581,41 @@ public class XWorkConverter extends DefaultTypeConverter {
         }
     }
 
+    /**
+     * Registers {@link TypeConversion} annotations found on the class' own fields. Only declared
+     * fields are read: {@link #buildConverterMapping(Class)} already walks the class hierarchy and
+     * calls this method once per class. Static and synthetic fields are skipped, which also makes
+     * this a no-op for interfaces.
+     */
+    private void processFieldAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Field field : clazz.getDeclaredFields()) {
+            if (Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) {
+                continue;
+            }
+            for (Annotation annotation : field.getAnnotations()) {
+                if (!(annotation instanceof TypeConversion tc)) {
+                    continue;
+                }
+                String name = StringUtils.isEmpty(tc.key()) ? field.getName() : tc.key();
+                String key = resolveKey(tc.type(), tc.rule(), name);
+                if (key == null) {
+                    // defensive: a field always has a name, so this is unreachable in practice
+                    LOG.warn("Ignoring @TypeConversion on field [{}#{}]: the key could not be resolved",
+                            clazz.getName(), field.getName());
+                    continue;
+                }
+                if (mapping.containsKey(key)) {
+                    LOG.debug("Skipping @TypeConversion on field [{}#{}]: key [{}] is already mapped by a higher precedence source",
+                            clazz.getName(), field.getName(), key);
+                    continue;
+                }
+                LOG.debug("TypeConversion [{}/{}] on field [{}] resolved to key [{}]",
+                        tc.converter(), tc.converterClass(), field.getName(), key);
+                annotationProcessor.process(mapping, tc, key);
+            }
+        }
+    }
+
 
     /**
      * Looks for converter mappings for the specified class, traversing up its class hierarchy and interfaces and adding
diff --git a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
index b791fc941..1ca4bc161 100644
--- a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
+++ b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
@@ -44,6 +44,7 @@ import org.apache.struts2.conversion.annotations.ConversionType;
 import org.apache.struts2.util.BareKeyConversionAction;
 import org.apache.struts2.util.CollidingKeyConversionAction;
 import org.apache.struts2.util.ExplicitKeyConversionAction;
+import org.apache.struts2.util.FieldConversionAction;
 import org.apache.struts2.util.MyBean;
 import org.apache.struts2.util.MyBeanAction;
 
@@ -896,6 +897,20 @@ public class XWorkConverterTest extends XWorkTestCase {
         assertEquals("true", freshConverter.getConverter(CollidingKeyConversionAction.class, "CreateIfNull_afterTheCollision"));
     }
 
+    public void testFieldLevelAnnotationDerivesKeyFromTheFieldName() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals("true", freshConverter.getConverter(FieldConversionAction.class, "CreateIfNull_fieldOnlyList"));
+    }
+
+    public void testMethodAnnotationWinsOverFieldAnnotation() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals(Long.class, freshConverter.getConverter(FieldConversionAction.class, "Key_contestedMap"));
+    }
+
     public static class CountingXWorkConverter extends XWorkConverter {
         final AtomicInteger builds = new AtomicInteger();
 
diff --git a/core/src/test/java/org/apache/struts2/util/FieldConversionAction.java b/core/src/test/java/org/apache/struts2/util/FieldConversionAction.java
new file mode 100644
index 000000000..920751988
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/util/FieldConversionAction.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Exercises field level {@link TypeConversion}: {@code fieldOnlyList} is annotated on the field
+ * alone, while {@code contestedMap} is annotated on both the field and its setter so the
+ * class &gt; method &gt; field precedence can be asserted.
+ */
+public class FieldConversionAction {
+
+    @TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+    private List fieldOnlyList = new ArrayList();
+
+    @TypeConversion(rule = ConversionRule.KEY, converterClass = String.class)
+    private Map contestedMap = new HashMap();
+
+    public List getFieldOnlyList() {
+        return fieldOnlyList;
+    }
+
+    public void setFieldOnlyList(List fieldOnlyList) {
+        this.fieldOnlyList = fieldOnlyList;
+    }
+
+    public Map getContestedMap() {
+        return contestedMap;
+    }
+
+    @TypeConversion(rule = ConversionRule.KEY, converterClass = Long.class)
+    public void setContestedMap(Map contestedMap) {
+        this.contestedMap = contestedMap;
+    }
+}


(struts) 03/14: WW-3871 docs: add implementation plan for @TypeConversion key derivation

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit a06198e4e8c57d3267a03baa35cba6eb1eedb750
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:06:32 2026 +0200

    WW-3871 docs: add implementation plan for @TypeConversion key derivation
    
    Seven TDD tasks covering ConversionRule#prefix(), the shared resolveKey
    helper, class- and field-level derivation, the break/continue and empty-key
    fixes, an end-to-end binding proof and the Javadoc updates. Refines the
    spec's resolveKey signature to take the two annotation attributes rather
    than the annotation instance, so it can be unit tested directly.
    
    Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
---
 ...-07-25-WW-3871-typeconversion-key-derivation.md | 1026 ++++++++++++++++++++
 ...WW-3871-typeconversion-key-derivation-design.md |    9 +-
 2 files changed, 1032 insertions(+), 3 deletions(-)

diff --git a/docs/superpowers/plans/2026-07-25-WW-3871-typeconversion-key-derivation.md b/docs/superpowers/plans/2026-07-25-WW-3871-typeconversion-key-derivation.md
new file mode 100644
index 000000000..b0351c147
--- /dev/null
+++ b/docs/superpowers/plans/2026-07-25-WW-3871-typeconversion-key-derivation.md
@@ -0,0 +1,1026 @@
+# WW-3871 `@TypeConversion` Key Derivation Implementation Plan
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+
+**Goal:** Let `@TypeConversion` accept a bare property name as its `key` at class, method and field level, deriving the `ConversionRule` prefix automatically, without breaking annotations that already spell the prefix out.
+
+**Architecture:** `ConversionRule` gains a `prefix()` method owning the rule-to-prefix table. `XWorkConverter` gains one static `resolveKey(type, rule, name)` used by all three annotation passes, and `addConverterMapping` splits into four named passes (properties file, class-level, method, field) with first-writer-wins precedence. `@TypeConversion` gains `ElementType.FIELD`.
+
+**Tech Stack:** Java 17, Maven, JUnit (see constraints), Log4j2, `org.apache.commons.lang3.StringUtils`.
+
+**Spec:** `docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md`
+
+## Global Constraints
+
+- **Branch:** work on `WW-3871-typeconversion-key-derivation` (already created, based on `main` @ `8a5323fbd`). Never commit to `main`.
+- **Commit messages:** must be prefixed with the ticket: `WW-3871 <type>(<scope>): <description>`. Types: `feat`, `fix`, `refactor`, `test`, `docs`, `chore`.
+- **Test framework:** core tests are JUnit 3/4, **never** JUnit 5. Classes extending `XWorkTestCase` (which extends `junit.framework.TestCase`) use `public void testXxx()` with **no** `@Test` annotation — an `@Test` there silently never runs. Standalone JUnit 4 classes (no superclass, `org.junit.Test` + `org.junit.Assert`) are also fine and are used in this module, e.g. `core/src/test/java/org/apache/struts2/LocaleProviderTest.java`.
+- **Build command:** `mvn test -DskipAssembly -pl core -Dtest=ClassName#methodName` for a single test; `mvn test -DskipAssembly -pl core` for the module.
+- **Licence header:** every new `.java` and `.properties` file must start with the Apache licence header — copy it verbatim from a neighbouring file in the same directory.
+- **Target version for `@since` tags:** `7.3.0`.
+- **No new dependencies.**
+
+---
+
+### Task 1: `ConversionRule.prefix()`
+
+**Files:**
+- Modify: `core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java`
+- Test (create): `core/src/test/java/org/apache/struts2/conversion/annotations/ConversionRuleTest.java`
+
+**Interfaces:**
+- Consumes: `DefaultObjectTypeDeterminer.KEY_PREFIX`, `ELEMENT_PREFIX`, `KEY_PROPERTY_PREFIX`, `CREATE_IF_NULL_PREFIX`, `DEPRECATED_ELEMENT_PREFIX` — public String constants in `org.apache.struts2.conversion.impl.DefaultObjectTypeDeterminer` (`"Key_"`, `"Element_"`, `"KeyProperty_"`, `"CreateIfNull_"`, `"Collection_"`).
+- Produces: `public String ConversionRule.prefix()` — returns the mapping-key prefix for the rule, `""` for `PROPERTY` and `MAP`. Never null.
+
+- [ ] **Step 1: Write the failing test**
+
+Create `core/src/test/java/org/apache/struts2/conversion/annotations/ConversionRuleTest.java` (Apache licence header first, copied from `ConversionRule.java`):
+
+```java
+package org.apache.struts2.conversion.annotations;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ConversionRuleTest {
+
+    @Test
+    public void prefixIsDefinedForEveryRule() {
+        assertEquals("", ConversionRule.PROPERTY.prefix());
+        assertEquals("", ConversionRule.MAP.prefix());
+        assertEquals("Collection_", ConversionRule.COLLECTION.prefix());
+        assertEquals("CreateIfNull_", ConversionRule.CREATE_IF_NULL.prefix());
+        assertEquals("Element_", ConversionRule.ELEMENT.prefix());
+        assertEquals("Key_", ConversionRule.KEY.prefix());
+        assertEquals("KeyProperty_", ConversionRule.KEY_PROPERTY.prefix());
+    }
+}
+```
+
+- [ ] **Step 2: Run it to make sure it fails**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=ConversionRuleTest`
+Expected: compilation failure — `cannot find symbol: method prefix()`.
+
+- [ ] **Step 3: Implement `prefix()`**
+
+In `ConversionRule.java`, add the import and the method. The enum body becomes:
+
+```java
+package org.apache.struts2.conversion.annotations;
+
+import org.apache.struts2.conversion.impl.DefaultObjectTypeDeterminer;
+
+/**
+ * <code>ConversionRule</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public enum ConversionRule {
+
+    PROPERTY, COLLECTION, MAP, KEY, KEY_PROPERTY, ELEMENT, CREATE_IF_NULL;
+
+    /**
+     * The prefix a conversion mapping key carries for this rule, as read back by
+     * {@link DefaultObjectTypeDeterminer}. {@code PROPERTY} and {@code MAP} have no prefix of their
+     * own: map and collection metadata is read through the {@code Key_} and {@code Element_} keys.
+     *
+     * @return the mapping key prefix, never null; an empty string when the rule has none
+     * @since 7.3.0
+     */
+    public String prefix() {
+        return switch (this) {
+            case COLLECTION -> DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX;
+            case CREATE_IF_NULL -> DefaultObjectTypeDeterminer.CREATE_IF_NULL_PREFIX;
+            case ELEMENT -> DefaultObjectTypeDeterminer.ELEMENT_PREFIX;
+            case KEY -> DefaultObjectTypeDeterminer.KEY_PREFIX;
+            case KEY_PROPERTY -> DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX;
+            case PROPERTY, MAP -> "";
+        };
+    }
+
+    @Override
+    public String toString() {
+        return super.toString().toUpperCase();
+    }
+}
+```
+
+The `switch` is deliberately exhaustive with no `default` branch: adding a rule then fails to compile until its prefix is decided.
+
+- [ ] **Step 4: Run the test and make sure it passes**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=ConversionRuleTest`
+Expected: PASS, 1 test.
+
+- [ ] **Step 5: Commit**
+
+```bash
+git add core/src/main/java/org/apache/struts2/conversion/annotations/ConversionRule.java \
+        core/src/test/java/org/apache/struts2/conversion/annotations/ConversionRuleTest.java
+git commit -m "WW-3871 feat(core): add ConversionRule#prefix() owning the rule-to-prefix table"
+```
+
+---
+
+### Task 2: Split `addConverterMapping` into named passes (pure refactor)
+
+No behaviour changes in this task — including the `break` statements, which stay wrong until Task 4. This exists so the later tasks touch small, readable methods.
+
+**Files:**
+- Modify: `core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java:496-548`
+
+**Interfaces:**
+- Produces: `private void processClassLevelAnnotations(Map<String, Object> mapping, Class clazz)` and `private void processMethodAnnotations(Map<String, Object> mapping, Class clazz)`, both called from `addConverterMapping`.
+
+- [ ] **Step 1: Run the existing tests to establish the baseline**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest='XWorkConverterTest+AnnotationXWorkConverterTest+MyBeanActionTest'`
+Expected: PASS. Record the test counts — the same tests must still pass at Step 3.
+
+- [ ] **Step 2: Extract the two passes**
+
+Replace the whole body of `addConverterMapping` (currently lines 496-548) with:
+
+```java
+    protected void addConverterMapping(Map<String, Object> mapping, Class clazz) {
+        // Process <clazz>-conversion.properties file
+        String converterFilename = buildConverterFilename(clazz);
+        fileProcessor.process(mapping, clazz, converterFilename);
+
+        processClassLevelAnnotations(mapping, clazz);
+        processMethodAnnotations(mapping, clazz);
+    }
+
+    /**
+     * Registers the {@link TypeConversion} entries declared by a class level {@link Conversion}
+     * annotation.
+     */
+    private void processClassLevelAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Annotation annotation : clazz.getAnnotations()) {
+            if (annotation instanceof Conversion conversion) {
+                for (TypeConversion tc : conversion.conversions()) {
+                    if (mapping.containsKey(tc.key())) {
+                        break;
+                    }
+                    if (LOG.isDebugEnabled()) {
+                        if (StringUtils.isEmpty(tc.key())) {
+                            LOG.debug("WARNING! key of @TypeConversion [{}/{}] applied to [{}] is empty!", tc.converter(), tc.converterClass(), clazz.getName());
+                        } else {
+                            LOG.debug("TypeConversion [{}/{}] with key: [{}]", tc.converter(), tc.converterClass(), tc.key());
+                        }
+                    }
+                    annotationProcessor.process(mapping, tc, tc.key());
+                }
+            }
+        }
+    }
+
+    /**
+     * Registers {@link TypeConversion} annotations found on the class' methods.
+     */
+    private void processMethodAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Method method : clazz.getMethods()) {
+            for (Annotation annotation : method.getAnnotations()) {
+                if (annotation instanceof TypeConversion tc) {
+                    String key = tc.key();
+                    // Default to the property name with prefix
+                    if (StringUtils.isEmpty(key)) {
+                        key = AnnotationUtils.resolvePropertyName(method);
+                        key = switch (tc.rule()) {
+                            case COLLECTION -> DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX + key;
+                            case CREATE_IF_NULL -> DefaultObjectTypeDeterminer.CREATE_IF_NULL_PREFIX + key;
+                            case ELEMENT -> DefaultObjectTypeDeterminer.ELEMENT_PREFIX + key;
+                            case KEY -> DefaultObjectTypeDeterminer.KEY_PREFIX + key;
+                            case KEY_PROPERTY -> DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX + key;
+                            default -> key;
+                        };
+                        LOG.debug("Retrieved key [{}] from method name [{}]", key, method.getName());
+                    }
+                    if (mapping.containsKey(key)) {
+                        break;
+                    }
+                    annotationProcessor.process(mapping, tc, key);
+                }
+            }
+        }
+    }
+```
+
+Note: the original code reused a local `Annotation[] annotations` variable across both loops; the extracted methods each iterate directly, so that variable disappears. Check whether `Annotation` and `Method` imports are still needed — they are, both extracted methods use them.
+
+- [ ] **Step 3: Run the same tests and confirm identical results**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest='XWorkConverterTest+AnnotationXWorkConverterTest+MyBeanActionTest'`
+Expected: PASS, same counts as Step 1.
+
+- [ ] **Step 4: Commit**
+
+```bash
+git add core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java
+git commit -m "WW-3871 refactor(core): split addConverterMapping into per-source passes"
+```
+
+---
+
+### Task 3: `resolveKey` helper, wired into the method pass
+
+**Files:**
+- Modify: `core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java`
+- Test (modify): `core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java`
+- Test fixture (create): `core/src/test/java/org/apache/struts2/util/ExplicitKeyConversionAction.java`
+
+**Interfaces:**
+- Consumes: `ConversionRule.prefix()` from Task 1; `processMethodAnnotations` from Task 2.
+- Produces: `static String resolveKey(ConversionType type, ConversionRule rule, String name)` on `XWorkConverter` — package-private static, returns the prefixed mapping key, or `null` when `name` is null or empty. Callers in Tasks 4 and 5 rely on this exact signature and on `null` meaning "skip this entry".
+
+- [ ] **Step 1: Write the failing unit tests for `resolveKey`**
+
+Append to `core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java` (a `XWorkTestCase` subclass — plain `testXxx` methods, no `@Test`):
+
+```java
+    public void testResolveKeyPrependsTheRulePrefix() {
+        assertEquals("KeyProperty_annotatedBeanMap",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY_PROPERTY, "annotatedBeanMap"));
+        assertEquals("Element_annotatedBeanList",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.ELEMENT, "annotatedBeanList"));
+        assertEquals("CreateIfNull_users",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.CREATE_IF_NULL, "users"));
+    }
+
+    public void testResolveKeyLeavesAnAlreadyPrefixedKeyAlone() {
+        assertEquals("KeyProperty_annotatedBeanMap",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY_PROPERTY, "KeyProperty_annotatedBeanMap"));
+        assertEquals("Key_beanMap",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY, "Key_beanMap"));
+    }
+
+    public void testResolveKeyDoesNotPrefixPropertyOrMapRules() {
+        assertEquals("someProperty",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.PROPERTY, "someProperty"));
+        assertEquals("keyValues",
+                XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.MAP, "keyValues"));
+    }
+
+    public void testResolveKeyNeverPrefixesApplicationScopedKeys() {
+        assertEquals("java.util.Date",
+                XWorkConverter.resolveKey(ConversionType.APPLICATION, ConversionRule.PROPERTY, "java.util.Date"));
+        assertEquals("java.util.Date",
+                XWorkConverter.resolveKey(ConversionType.APPLICATION, ConversionRule.ELEMENT, "java.util.Date"));
+    }
+
+    public void testResolveKeyReturnsNullWhenNoNameIsAvailable() {
+        assertNull(XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.PROPERTY, null));
+        assertNull(XWorkConverter.resolveKey(ConversionType.CLASS, ConversionRule.KEY, ""));
+    }
+```
+
+Add these imports to that test class if not already present:
+
+```java
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.ConversionType;
+```
+
+- [ ] **Step 2: Run them to make sure they fail**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=XWorkConverterTest`
+Expected: compilation failure — `cannot find symbol: method resolveKey(...)`.
+
+- [ ] **Step 3: Implement `resolveKey` and use it in the method pass**
+
+Add to `XWorkConverter` (place it just above `addConverterMapping`):
+
+```java
+    /**
+     * Resolves the conversion mapping key for an annotation: the given name carrying the
+     * {@link ConversionRule}'s prefix. A name that already starts with that prefix is returned
+     * unchanged, so annotations that spell the prefix out keep working.
+     *
+     * @param type the annotation's {@link ConversionType}; APPLICATION keys are class names and are never prefixed
+     * @param rule the annotation's {@link ConversionRule}
+     * @param name an explicit key or a property name derived from a method or field
+     * @return the mapping key, or null when no name is available and the entry must be skipped
+     * @since 7.3.0
+     */
+    static String resolveKey(ConversionType type, ConversionRule rule, String name) {
+        if (StringUtils.isEmpty(name)) {
+            return null;
+        }
+        if (type == ConversionType.APPLICATION) {
+            return name;
+        }
+        String prefix = rule.prefix();
+        return name.startsWith(prefix) ? name : prefix + name;
+    }
+```
+
+Add the imports `org.apache.struts2.conversion.annotations.ConversionRule` and `org.apache.struts2.conversion.annotations.ConversionType`.
+
+Then replace the body of `processMethodAnnotations` (from Task 2) with:
+
+```java
+    private void processMethodAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Method method : clazz.getMethods()) {
+            for (Annotation annotation : method.getAnnotations()) {
+                if (!(annotation instanceof TypeConversion tc)) {
+                    continue;
+                }
+                String name = StringUtils.isEmpty(tc.key()) ? AnnotationUtils.resolvePropertyName(method) : tc.key();
+                String key = resolveKey(tc.type(), tc.rule(), name);
+                if (key == null) {
+                    LOG.warn("Ignoring @TypeConversion on [{}#{}]: no key was given and no property name could be derived from the method",
+                            clazz.getName(), method.getName());
+                    continue;
+                }
+                if (mapping.containsKey(key)) {
+                    continue;
+                }
+                LOG.debug("TypeConversion [{}/{}] on method [{}] resolved to key [{}]",
+                        tc.converter(), tc.converterClass(), method.getName(), key);
+                annotationProcessor.process(mapping, tc, key);
+            }
+        }
+    }
+```
+
+Two behaviour changes land here: an explicit method-level key is now normalised through `resolveKey`, and the `break` becomes `continue` so one already-mapped key no longer aborts the method's remaining annotations. `DefaultObjectTypeDeterminer` may no longer be referenced by this class — remove the import only if the compiler says it is unused.
+
+- [ ] **Step 4: Run the unit tests and make sure they pass**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=XWorkConverterTest`
+Expected: PASS.
+
+- [ ] **Step 5: Write the failing fixture test for explicit-key normalisation**
+
+Create `core/src/test/java/org/apache/struts2/util/ExplicitKeyConversionAction.java` (Apache licence header copied from `MyBeanAction.java`):
+
+```java
+package org.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Declares a method level {@link TypeConversion} with an explicit, unprefixed key. Before WW-3871
+ * this registered a bare {@code bareList} mapping that nothing ever read.
+ */
+public class ExplicitKeyConversionAction {
+
+    private List bareList = new ArrayList();
+
+    public List getBareList() {
+        return bareList;
+    }
+
+    @TypeConversion(key = "bareList", rule = ConversionRule.CREATE_IF_NULL, value = "true")
+    public void setBareList(List bareList) {
+        this.bareList = bareList;
+    }
+}
+```
+
+Append to `XWorkConverterTest`:
+
+```java
+    public void testExplicitMethodKeyGetsTheRulePrefix() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals("true", freshConverter.getConverter(ExplicitKeyConversionAction.class, "CreateIfNull_bareList"));
+        assertNull(freshConverter.getConverter(ExplicitKeyConversionAction.class, "bareList"));
+    }
+```
+
+Add the import `org.apache.struts2.util.ExplicitKeyConversionAction` if the test class does not already import that package wholesale.
+
+- [ ] **Step 6: Run it and confirm it passes**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=XWorkConverterTest#testExplicitMethodKeyGetsTheRulePrefix`
+Expected: PASS.
+
+- [ ] **Step 7: Run the wider conversion suite for regressions**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest='XWorkConverterTest+AnnotationXWorkConverterTest+MyBeanActionTest+XWorkBasicConverterTest'`
+Expected: PASS.
+
+- [ ] **Step 8: Commit**
+
+```bash
+git add core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java \
+        core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java \
+        core/src/test/java/org/apache/struts2/util/ExplicitKeyConversionAction.java
+git commit -m "WW-3871 feat(core): derive conversion mapping keys through a single resolver"
+```
+
+---
+
+### Task 4: Class-level bare keys, `continue` fix, empty-key warning
+
+**Files:**
+- Modify: `core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java` (`processClassLevelAnnotations`)
+- Test fixture (create): `core/src/test/java/org/apache/struts2/util/BareKeyConversionAction.java`
+- Test fixture (create): `core/src/test/java/org/apache/struts2/util/CollidingKeyConversionAction.java`
+- Test resource (create): `core/src/test/resources/org/apache/struts2/util/CollidingKeyConversionAction-conversion.properties`
+- Test (modify): `core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java`
+
+**Interfaces:**
+- Consumes: `XWorkConverter.resolveKey(ConversionType, ConversionRule, String)` from Task 3.
+- Produces: nothing new; changes `processClassLevelAnnotations` behaviour only.
+
+- [ ] **Step 1: Write the failing tests**
+
+Create `core/src/test/java/org/apache/struts2/util/BareKeyConversionAction.java` (licence header first):
+
+```java
+package org.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The class level counterpart of {@link MyBeanAction}, declaring the same four conversions with
+ * bare property names instead of spelled-out prefixes.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.ELEMENT, converterClass = MyBean.class),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.ELEMENT, converterClass = MyBean.class)
+        })
+public class BareKeyConversionAction {
+
+    private Map annotatedBeanMap = new HashMap();
+    private List annotatedBeanList = new ArrayList();
+
+    public Map getAnnotatedBeanMap() {
+        return annotatedBeanMap;
+    }
+
+    public void setAnnotatedBeanMap(Map annotatedBeanMap) {
+        this.annotatedBeanMap = annotatedBeanMap;
+    }
+
+    public List getAnnotatedBeanList() {
+        return annotatedBeanList;
+    }
+
+    public void setAnnotatedBeanList(List annotatedBeanList) {
+        this.annotatedBeanList = annotatedBeanList;
+    }
+}
+```
+
+Note the same bare key appears twice with different rules — that is the point: the rule, not the key, disambiguates them.
+
+Create `core/src/test/java/org/apache/struts2/util/CollidingKeyConversionAction.java` (licence header first):
+
+```java
+package org.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The first conversion entry collides with a key already supplied by
+ * {@code CollidingKeyConversionAction-conversion.properties}; the second must still be registered.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(key = "fromProperties", rule = ConversionRule.CREATE_IF_NULL, value = "false"),
+                @TypeConversion(key = "afterTheCollision", rule = ConversionRule.CREATE_IF_NULL, value = "true")
+        })
+public class CollidingKeyConversionAction {
+
+    private List afterTheCollision = new ArrayList();
+
+    public List getAfterTheCollision() {
+        return afterTheCollision;
+    }
+
+    public void setAfterTheCollision(List afterTheCollision) {
+        this.afterTheCollision = afterTheCollision;
+    }
+}
+```
+
+Create `core/src/test/resources/org/apache/struts2/util/CollidingKeyConversionAction-conversion.properties` (comment-style Apache licence header copied verbatim from `core/src/test/resources/org/apache/struts2/test/DataAware-conversion.properties`, then):
+
+```properties
+CreateIfNull_fromProperties=true
+```
+
+Append to `XWorkConverterTest`:
+
+```java
+    public void testClassLevelBareKeysGetTheRulePrefix() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals("id", freshConverter.getConverter(BareKeyConversionAction.class, "KeyProperty_annotatedBeanMap"));
+        assertEquals(MyBean.class, freshConverter.getConverter(BareKeyConversionAction.class, "Element_annotatedBeanMap"));
+        assertEquals("id", freshConverter.getConverter(BareKeyConversionAction.class, "KeyProperty_annotatedBeanList"));
+        assertEquals(MyBean.class, freshConverter.getConverter(BareKeyConversionAction.class, "Element_annotatedBeanList"));
+    }
+
+    public void testClassLevelBareKeysMatchTheSpelledOutForm() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        for (String key : new String[]{"KeyProperty_annotatedBeanMap", "Element_annotatedBeanMap",
+                "KeyProperty_annotatedBeanList", "Element_annotatedBeanList"}) {
+            assertEquals("mismatch for " + key,
+                    freshConverter.getConverter(MyBeanAction.class, key),
+                    freshConverter.getConverter(BareKeyConversionAction.class, key));
+        }
+    }
+
+    public void testClassLevelEntriesAfterAKeyCollisionAreStillRegistered() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        // supplied by the -conversion.properties file, so the annotation must not overwrite it
+        assertEquals("true", freshConverter.getConverter(CollidingKeyConversionAction.class, "CreateIfNull_fromProperties"));
+        // the entry after the collision used to be dropped by `break`
+        assertEquals("true", freshConverter.getConverter(CollidingKeyConversionAction.class, "CreateIfNull_afterTheCollision"));
+    }
+```
+
+Add imports for `org.apache.struts2.util.BareKeyConversionAction`, `org.apache.struts2.util.CollidingKeyConversionAction`, `org.apache.struts2.util.MyBean` and `org.apache.struts2.util.MyBeanAction` as needed.
+
+- [ ] **Step 2: Run them to make sure they fail**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest='XWorkConverterTest#testClassLevelBareKeysGetTheRulePrefix+XWorkConverterTest#testClassLevelEntriesAfterAKeyCollisionAreStillRegistered'`
+Expected: FAIL — bare keys resolve to null (no prefix applied), and the post-collision entry is missing.
+
+- [ ] **Step 3: Rewrite `processClassLevelAnnotations`**
+
+```java
+    private void processClassLevelAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Annotation annotation : clazz.getAnnotations()) {
+            if (!(annotation instanceof Conversion conversion)) {
+                continue;
+            }
+            for (TypeConversion tc : conversion.conversions()) {
+                String key = resolveKey(tc.type(), tc.rule(), tc.key());
+                if (key == null) {
+                    LOG.warn("Ignoring @TypeConversion [{}/{}] declared on [{}]: no key was given and a class level annotation has no property name to derive one from",
+                            tc.converter(), tc.converterClass(), clazz.getName());
+                    continue;
+                }
+                if (mapping.containsKey(key)) {
+                    continue;
+                }
+                LOG.debug("TypeConversion [{}/{}] declared on [{}] resolved to key [{}]",
+                        tc.converter(), tc.converterClass(), clazz.getName(), key);
+                annotationProcessor.process(mapping, tc, key);
+            }
+        }
+    }
+```
+
+Three changes: `resolveKey` is applied, the `containsKey` guard now tests the *resolved* key and `continue`s instead of `break`ing, and an unresolvable key is skipped with a WARN rather than registering a `""` mapping.
+
+- [ ] **Step 4: Run the new tests and make sure they pass**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=XWorkConverterTest`
+Expected: PASS.
+
+- [ ] **Step 5: Run the conversion suite for regressions**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest='XWorkConverterTest+AnnotationXWorkConverterTest+MyBeanActionTest+XWorkBasicConverterTest+StringConverterTest'`
+Expected: PASS. `MyBeanActionTest` passing here is the backward-compatibility proof: its fixture still spells out every prefix.
+
+- [ ] **Step 6: Commit**
+
+```bash
+git add core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java \
+        core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java \
+        core/src/test/java/org/apache/struts2/util/BareKeyConversionAction.java \
+        core/src/test/java/org/apache/struts2/util/CollidingKeyConversionAction.java \
+        core/src/test/resources/org/apache/struts2/util/CollidingKeyConversionAction-conversion.properties
+git commit -m "WW-3871 fix(core): derive class level conversion keys and stop dropping later entries"
+```
+
+---
+
+### Task 5: Field-level `@TypeConversion`
+
+**Files:**
+- Modify: `core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java:153` (`@Target`)
+- Modify: `core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java` (`addConverterMapping`, new `processFieldAnnotations`)
+- Test fixture (create): `core/src/test/java/org/apache/struts2/util/FieldConversionAction.java`
+- Test (modify): `core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java`
+
+**Interfaces:**
+- Consumes: `XWorkConverter.resolveKey(ConversionType, ConversionRule, String)` from Task 3.
+- Produces: `private void processFieldAnnotations(Map<String, Object> mapping, Class clazz)`, called last from `addConverterMapping`.
+
+- [ ] **Step 1: Write the failing test**
+
+Create `core/src/test/java/org/apache/struts2/util/FieldConversionAction.java` (licence header first):
+
+```java
+package org.apache.struts2.util;
+
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Exercises field level {@link TypeConversion}: {@code fieldOnlyList} is annotated on the field
+ * alone, while {@code contestedMap} is annotated on both the field and its setter so the
+ * class &gt; method &gt; field precedence can be asserted.
+ */
+public class FieldConversionAction {
+
+    @TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+    private List fieldOnlyList = new ArrayList();
+
+    @TypeConversion(rule = ConversionRule.KEY, converterClass = String.class)
+    private Map contestedMap = new HashMap();
+
+    public List getFieldOnlyList() {
+        return fieldOnlyList;
+    }
+
+    public void setFieldOnlyList(List fieldOnlyList) {
+        this.fieldOnlyList = fieldOnlyList;
+    }
+
+    public Map getContestedMap() {
+        return contestedMap;
+    }
+
+    @TypeConversion(rule = ConversionRule.KEY, converterClass = Long.class)
+    public void setContestedMap(Map contestedMap) {
+        this.contestedMap = contestedMap;
+    }
+}
+```
+
+Append to `XWorkConverterTest`:
+
+```java
+    public void testFieldLevelAnnotationDerivesKeyFromTheFieldName() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals("true", freshConverter.getConverter(FieldConversionAction.class, "CreateIfNull_fieldOnlyList"));
+    }
+
+    public void testMethodAnnotationWinsOverFieldAnnotation() {
+        XWorkConverter freshConverter = container.inject(XWorkConverter.class);
+        freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());
+
+        assertEquals(Long.class, freshConverter.getConverter(FieldConversionAction.class, "Key_contestedMap"));
+    }
+```
+
+Add the import for `org.apache.struts2.util.FieldConversionAction`.
+
+- [ ] **Step 2: Run it to make sure it fails**
+
+Run: `mvn test-compile -DskipAssembly -pl core`
+Expected: compilation failure — `annotation type org.apache.struts2.conversion.annotations.TypeConversion is not applicable to this kind of declaration` on the two annotated fields.
+
+- [ ] **Step 3: Widen the annotation target**
+
+In `TypeConversion.java`, change line 153:
+
+```java
+@Target({ElementType.METHOD, ElementType.FIELD})
+```
+
+- [ ] **Step 4: Run the test again — it must now fail on the assertion, not on compilation**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=XWorkConverterTest#testFieldLevelAnnotationDerivesKeyFromTheFieldName`
+Expected: FAIL — `expected:<true> but was:<null>`; the annotation compiles but nothing reads it yet.
+
+- [ ] **Step 5: Add the field pass**
+
+In `XWorkConverter`, add the call at the end of `addConverterMapping`:
+
+```java
+    protected void addConverterMapping(Map<String, Object> mapping, Class clazz) {
+        // Process <clazz>-conversion.properties file
+        String converterFilename = buildConverterFilename(clazz);
+        fileProcessor.process(mapping, clazz, converterFilename);
+
+        processClassLevelAnnotations(mapping, clazz);
+        processMethodAnnotations(mapping, clazz);
+        processFieldAnnotations(mapping, clazz);
+    }
+```
+
+and the new method after `processMethodAnnotations`:
+
+```java
+    /**
+     * Registers {@link TypeConversion} annotations found on the class' own fields. Only declared
+     * fields are read: {@link #buildConverterMapping(Class)} already walks the class hierarchy and
+     * calls this method once per class. Static and synthetic fields are skipped, which also makes
+     * this a no-op for interfaces.
+     */
+    private void processFieldAnnotations(Map<String, Object> mapping, Class clazz) {
+        for (Field field : clazz.getDeclaredFields()) {
+            if (Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) {
+                continue;
+            }
+            for (Annotation annotation : field.getAnnotations()) {
+                if (!(annotation instanceof TypeConversion tc)) {
+                    continue;
+                }
+                String name = StringUtils.isEmpty(tc.key()) ? field.getName() : tc.key();
+                String key = resolveKey(tc.type(), tc.rule(), name);
+                if (key == null) {
+                    // defensive: a field always has a name, so this is unreachable in practice
+                    LOG.warn("Ignoring @TypeConversion on field [{}#{}]: the key could not be resolved",
+                            clazz.getName(), field.getName());
+                    continue;
+                }
+                if (mapping.containsKey(key)) {
+                    LOG.debug("Skipping @TypeConversion on field [{}#{}]: key [{}] is already mapped by a higher precedence source",
+                            clazz.getName(), field.getName(), key);
+                    continue;
+                }
+                LOG.debug("TypeConversion [{}/{}] on field [{}] resolved to key [{}]",
+                        tc.converter(), tc.converterClass(), field.getName(), key);
+                annotationProcessor.process(mapping, tc, key);
+            }
+        }
+    }
+```
+
+Add the imports `java.lang.reflect.Field` and `java.lang.reflect.Modifier`.
+
+- [ ] **Step 6: Run the new tests and make sure they pass**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=XWorkConverterTest`
+Expected: PASS, including `testMethodAnnotationWinsOverFieldAnnotation` — the method pass runs first and claims `Key_contestedMap` with `Long.class`.
+
+- [ ] **Step 7: Run the full core module**
+
+Run: `mvn test -DskipAssembly -pl core`
+Expected: PASS. This is the first full run; field scanning now touches every class the converter maps, so a broad run is warranted here rather than at the end.
+
+- [ ] **Step 8: Commit**
+
+```bash
+git add core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java \
+        core/src/main/java/org/apache/struts2/conversion/impl/XWorkConverter.java \
+        core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java \
+        core/src/test/java/org/apache/struts2/util/FieldConversionAction.java
+git commit -m "WW-3871 feat(core): support @TypeConversion on fields"
+```
+
+---
+
+### Task 6: End-to-end proof through the action lifecycle
+
+The unit tests assert mapping contents; this asserts that bare keys actually bind request parameters, through the same path `MyBeanActionTest` exercises.
+
+**Files:**
+- Test fixture (create): `core/src/test/java/org/apache/struts2/util/MyBeanBareKeyAction.java`
+- Test resource (modify): `core/src/test/resources/xwork-sample.xml:128-132` (add a sibling action)
+- Test (modify): `core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java`
+
+**Interfaces:**
+- Consumes: everything from Tasks 3-5.
+- Produces: action name `MyBeanBareKey` in `xwork-sample.xml`.
+
+- [ ] **Step 1: Write the failing test**
+
+Create `core/src/test/java/org/apache/struts2/util/MyBeanBareKeyAction.java` (licence header first) — a copy of `MyBeanAction` with bare class-level keys and no `beanList`/`beanMap` properties:
+
+```java
+package org.apache.struts2.util;
+
+import org.apache.struts2.action.Action;
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * {@link MyBeanAction} restated with bare property names as conversion keys. Both must bind
+ * identically; {@code MyBeanAction} keeps the spelled-out prefixes so the old form stays covered.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.ELEMENT, converterClass = MyBean.class),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.ELEMENT, converterClass = MyBean.class)
+        })
+public class MyBeanBareKeyAction implements Action {
+
+    private Map annotatedBeanMap = new HashMap();
+    private List annotatedBeanList = new ArrayList();
+
+    public Map getAnnotatedBeanMap() {
+        return annotatedBeanMap;
+    }
+
+    @TypeConversion(rule = ConversionRule.KEY, converterClass = Long.class)
+    public void setAnnotatedBeanMap(Map annotatedBeanMap) {
+        this.annotatedBeanMap = annotatedBeanMap;
+    }
+
+    public List getAnnotatedBeanList() {
+        return annotatedBeanList;
+    }
+
+    @TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+    public void setAnnotatedBeanList(List annotatedBeanList) {
+        this.annotatedBeanList = annotatedBeanList;
+    }
+
+    public String execute() throws Exception {
+        return SUCCESS;
+    }
+}
+```
+
+Register it in `core/src/test/resources/xwork-sample.xml`, immediately after the existing `MyBean` action (line 132):
+
+```xml
+        <action name="MyBeanBareKey" class="org.apache.struts2.util.MyBeanBareKeyAction">
+            <interceptor-ref name="debugStack"/>
+            <interceptor-ref name="defaultStack"/>
+            <result name="success" type="mock"/>
+        </action>
+```
+
+Append to `MyBeanActionTest`:
+
+```java
+    public void testBareConversionKeysBindTheSameWayAsPrefixedOnes() throws Exception {
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("annotatedBeanList(1234567890).name", "This is the bla bean by annotation");
+        params.put("annotatedBeanMap[1234567891].id", "1234567891");
+        params.put("annotatedBeanMap[1234567891].name", "This is the 2nd bla bean by annotation");
+
+        ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBeanBareKey", null, extraContext.getContextMap());
+        proxy.execute();
+        MyBeanBareKeyAction action = (MyBeanBareKeyAction) proxy.getInvocation().getAction();
+
+        // CreateIfNull_annotatedBeanList + Element_annotatedBeanList
+        assertEquals(1, action.getAnnotatedBeanList().size());
+        assertEquals(MyBean.class, action.getAnnotatedBeanList().get(0).getClass());
+        assertEquals("This is the bla bean by annotation",
+                proxy.getInvocation().getStack().findValue("annotatedBeanList.get(0).name"));
+
+        // Key_annotatedBeanMap makes the key a Long, Element_annotatedBeanMap makes the value a MyBean
+        assertTrue(action.getAnnotatedBeanMap().containsKey(1234567891L));
+        assertEquals(MyBean.class, action.getAnnotatedBeanMap().get(1234567891L).getClass());
+        assertEquals("This is the 2nd bla bean by annotation",
+                proxy.getInvocation().getStack().findValue("annotatedBeanMap.get(1234567891L).name"));
+    }
+```
+
+Unlike the existing tests in this class, this one lets exceptions propagate rather than catching and calling `fail()` — a stack trace from the runner is more useful than a bare failure.
+
+- [ ] **Step 2: Run it — it must pass on the first try**
+
+This task adds no production code, so there is no red phase: Tasks 3-5 already implement the behaviour and this test only proves it reaches the action. A failure here is a real defect in those tasks, not a missing feature — debug it there rather than adjusting this test.
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=MyBeanActionTest#testBareConversionKeysBindTheSameWayAsPrefixedOnes`
+Expected: PASS.
+
+- [ ] **Step 3: Confirm the old form still binds**
+
+Run: `mvn test -DskipAssembly -pl core -Dtest=MyBeanActionTest`
+Expected: PASS — all three tests, including the two pre-existing ones against the spelled-out fixture.
+
+- [ ] **Step 4: Commit**
+
+```bash
+git add core/src/test/java/org/apache/struts2/util/MyBeanBareKeyAction.java \
+        core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java \
+        core/src/test/resources/xwork-sample.xml
+git commit -m "WW-3871 test(core): assert bare conversion keys bind through the action lifecycle"
+```
+
+---
+
+### Task 7: Documentation
+
+**Files:**
+- Modify: `core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java` (class Javadoc: usage snippet, parameter table, example)
+
+**Interfaces:**
+- Consumes: the behaviour built in Tasks 1-5.
+- Produces: nothing code-facing.
+
+- [ ] **Step 1: Update the usage snippet**
+
+Replace the `usage` snippet body (line 51) with:
+
+```java
+ * <p>The TypeConversion annotation can be applied at field and method level.</p>
+```
+
+- [ ] **Step 2: Update the `key` row of the parameter table**
+
+Replace the `key` row (lines 67-72) with:
+
+```java
+ * <tr>
+ * <td>key</td>
+ * <td>no</td>
+ * <td>The annotated property/field name</td>
+ * <td>The property name the rule applies to. The matching prefix for the given rule
+ * (<code>Key_</code>, <code>Element_</code>, <code>KeyProperty_</code>, <code>CreateIfNull_</code>)
+ * is prepended automatically unless the key already carries it. Required on TYPE level annotations,
+ * where there is no member name to derive it from.</td>
+ * </tr>
+```
+
+- [ ] **Step 3: Update the `key()` attribute Javadoc**
+
+Replace the Javadoc on `key()` (lines 157-163) with:
+
+```java
+    /**
+     * The property name this conversion applies to. Optional on fields and methods, where it
+     * defaults to the property name; required on TYPE level annotations.
+     *
+     * <p>The prefix matching the declared {@link ConversionRule} is prepended automatically, so
+     * {@code @TypeConversion(key = "users", rule = ConversionRule.CREATE_IF_NULL, value = "true")}
+     * and {@code @TypeConversion(key = "CreateIfNull_users", ...)} are equivalent.</p>
+     *
+     * @return key
+     * @since 7.3.0 the rule prefix is derived; previously the full key had to be spelled out
+     */
+```
+
+- [ ] **Step 4: Simplify the example**
+
+In the example snippet, add a field-level case and drop a redundant prefix. Replace the `setUsers` example (lines 132-135) with:
+
+```java
+ *   &#64;TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+ *   private List users = null;
+ *
+ *   &#64;TypeConversion(rule = ConversionRule.COLLECTION, converterClass = String.class)
+ *   public void setUsers( List users ) {
+ *       this.users = users;
+ *   }
+```
+
+- [ ] **Step 5: Verify the Javadoc builds**
+
+Run: `mvn javadoc:javadoc -DskipAssembly -pl core -q`
+Expected: no errors on `TypeConversion.java` or `ConversionRule.java`. Pre-existing warnings elsewhere in the module are not this task's concern.
+
+- [ ] **Step 6: Run the full core suite one last time**
+
+Run: `mvn test -DskipAssembly -pl core`
+Expected: PASS.
+
+- [ ] **Step 7: Commit**
+
+```bash
+git add core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
+git commit -m "WW-3871 docs(core): document conversion key derivation and field level support"
+```
+
+---
+
+## Verification Checklist
+
+Before opening the PR:
+
+- [ ] `mvn test -DskipAssembly -pl core` passes in full
+- [ ] `MyBeanActionTest` still passes with its original spelled-out prefixes untouched — the backward-compatibility guarantee
+- [ ] `git log --oneline main..HEAD` shows every commit prefixed `WW-3871`
+- [ ] PR title: `WW-3871 Derive ConversionRule prefixes for @TypeConversion keys`
+- [ ] PR body links the ticket: `Fixes [WW-3871](https://issues.apache.org/jira/browse/WW-3871)`
+- [ ] This is not a security patch (no OGNL evaluation, parameter filtering, upload or auth path is touched), so a public PR is appropriate
diff --git a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
index 5e957a7e6..150d861a4 100644
--- a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
+++ b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
@@ -78,18 +78,21 @@ An exhaustive `switch` over the enum means a future rule cannot silently miss a
 ### 2. One key resolver in `XWorkConverter`
 
 ```java
-static String resolveKey(TypeConversion tc, String name) {
+static String resolveKey(ConversionType type, ConversionRule rule, String name) {
     if (name == null || name.isEmpty()) {
         return null;                        // caller skips the entry and logs WARN
     }
-    if (tc.type() == ConversionType.APPLICATION) {
+    if (type == ConversionType.APPLICATION) {
         return name;                        // key is a class name, never prefixed
     }
-    String prefix = tc.rule().prefix();
+    String prefix = rule.prefix();
     return name.startsWith(prefix) ? name : prefix + name;
 }
 ```
 
+It takes the two annotation attributes rather than the `TypeConversion` instance so it can be unit
+tested directly — annotation instances are awkward to construct in a test.
+
 All three annotation passes route both explicit keys and derived property names through this
 function, so the three call sites cannot drift apart.
 


(struts) 02/14: WW-3871 docs: note interaction with the 7.3.0 converter mapping cache

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit f3952e487165f9ab5500ea0cb55dd0167e098743
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:00:57 2026 +0200

    WW-3871 docs: note interaction with the 7.3.0 converter mapping cache
    
    Records that addConverterMapping runs inside the computeMappingIfAbsent
    builder introduced by WW-5539, which executes outside any lock, so the new
    field pass adds no deadlock risk but must stay side-effect free.
    
    Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
---
 ...07-25-WW-3871-typeconversion-key-derivation-design.md | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
index 340968138..5e957a7e6 100644
--- a/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
+++ b/docs/superpowers/specs/2026-07-25-WW-3871-typeconversion-key-derivation-design.md
@@ -133,7 +133,21 @@ It skips `static` and synthetic fields, which also makes the interface case a no
 (`getDeclaredFields()` on an interface returns its constants). A field's own name is the property
 name; no getter/setter parsing is involved.
 
-### 4. Error handling
+### 4. Interaction with the 7.3.0 mapping cache
+
+`addConverterMapping` runs inside the builder that `XWorkConverter.buildConverterMapping` hands to
+`TypeConverterHolder.computeMappingIfAbsent` (WW-5539). That builder deliberately executes **outside**
+any lock — `StrutsTypeConverterHolder.java:171-188` documents why: it instantiates, and under
+`SpringObjectFactory` autowires, arbitrary user-supplied `TypeConverter`s, so running it under a
+`ConcurrentHashMap` bin lock would risk `IllegalStateException("Recursive update")` or self-deadlock
+if any of that re-enters conversion.
+
+The new field pass instantiates converters exactly as the existing method pass does, so it inherits
+that safety and adds no new hazard. The one consequence to respect: under first-access contention the
+builder may run more than once for the same class, so every pass must stay free of side effects
+outside the `mapping` map it is handed.
+
+### 5. Error handling
 
 | Situation | Today | After |
 |---|---|---|


(struts) 09/14: WW-3871 test(core): assert bare conversion keys bind through the action lifecycle

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit af603fa692841ae593bb846dbb24217f25aeba6b
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 15:38:59 2026 +0200

    WW-3871 test(core): assert bare conversion keys bind through the action lifecycle
    
    Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
---
 .../org/apache/struts2/util/MyBeanActionTest.java  | 25 ++++++++
 .../apache/struts2/util/MyBeanBareKeyAction.java   | 68 ++++++++++++++++++++++
 core/src/test/resources/xwork-sample.xml           |  6 ++
 3 files changed, 99 insertions(+)

diff --git a/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java b/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java
index 98c836d5b..3f19efbfe 100644
--- a/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java
+++ b/core/src/test/java/org/apache/struts2/util/MyBeanActionTest.java
@@ -126,6 +126,31 @@ public class MyBeanActionTest extends XWorkTestCase {
         }
     }
 
+    public void testBareConversionKeysBindTheSameWayAsPrefixedOnes() throws Exception {
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("annotatedBeanList(1234567890).name", "This is the bla bean by annotation");
+        params.put("annotatedBeanMap[1234567891].id", "1234567891");
+        params.put("annotatedBeanMap[1234567891].name", "This is the 2nd bla bean by annotation");
+
+        ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBeanBareKey", null, extraContext.getContextMap());
+        proxy.execute();
+        MyBeanBareKeyAction action = (MyBeanBareKeyAction) proxy.getInvocation().getAction();
+
+        // CreateIfNull_annotatedBeanList + Element_annotatedBeanList
+        assertEquals(1, action.getAnnotatedBeanList().size());
+        assertEquals(MyBean.class, action.getAnnotatedBeanList().get(0).getClass());
+        assertEquals("This is the bla bean by annotation",
+                proxy.getInvocation().getStack().findValue("annotatedBeanList.get(0).name"));
+
+        // Key_annotatedBeanMap makes the key a Long, Element_annotatedBeanMap makes the value a MyBean
+        assertTrue(action.getAnnotatedBeanMap().containsKey(1234567891L));
+        assertEquals(MyBean.class, action.getAnnotatedBeanMap().get(1234567891L).getClass());
+        assertEquals("This is the 2nd bla bean by annotation",
+                proxy.getInvocation().getStack().findValue("annotatedBeanMap.get(1234567891L).name"));
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
diff --git a/core/src/test/java/org/apache/struts2/util/MyBeanBareKeyAction.java b/core/src/test/java/org/apache/struts2/util/MyBeanBareKeyAction.java
new file mode 100644
index 000000000..ebc232f03
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/util/MyBeanBareKeyAction.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.struts2.util;
+
+import org.apache.struts2.action.Action;
+import org.apache.struts2.conversion.annotations.Conversion;
+import org.apache.struts2.conversion.annotations.ConversionRule;
+import org.apache.struts2.conversion.annotations.TypeConversion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * {@link MyBeanAction} restated with bare property names as conversion keys. Both must bind
+ * identically; {@code MyBeanAction} keeps the spelled-out prefixes so the old form stays covered.
+ */
+@Conversion(
+        conversions = {
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanMap", rule = ConversionRule.ELEMENT, converterClass = MyBean.class),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.KEY_PROPERTY, value = "id"),
+                @TypeConversion(key = "annotatedBeanList", rule = ConversionRule.ELEMENT, converterClass = MyBean.class)
+        })
+public class MyBeanBareKeyAction implements Action {
+
+    private Map annotatedBeanMap = new HashMap();
+    private List annotatedBeanList = new ArrayList();
+
+    public Map getAnnotatedBeanMap() {
+        return annotatedBeanMap;
+    }
+
+    @TypeConversion(rule = ConversionRule.KEY, converterClass = Long.class)
+    public void setAnnotatedBeanMap(Map annotatedBeanMap) {
+        this.annotatedBeanMap = annotatedBeanMap;
+    }
+
+    public List getAnnotatedBeanList() {
+        return annotatedBeanList;
+    }
+
+    @TypeConversion(rule = ConversionRule.CREATE_IF_NULL, value = "true")
+    public void setAnnotatedBeanList(List annotatedBeanList) {
+        this.annotatedBeanList = annotatedBeanList;
+    }
+
+    public String execute() throws Exception {
+        return SUCCESS;
+    }
+}
diff --git a/core/src/test/resources/xwork-sample.xml b/core/src/test/resources/xwork-sample.xml
index 5bc189d82..456dc6dad 100644
--- a/core/src/test/resources/xwork-sample.xml
+++ b/core/src/test/resources/xwork-sample.xml
@@ -131,6 +131,12 @@
             <result name="success" type="mock"/>
         </action>
 
+        <action name="MyBeanBareKey" class="org.apache.struts2.util.MyBeanBareKeyAction">
+            <interceptor-ref name="debugStack"/>
+            <interceptor-ref name="defaultStack"/>
+            <result name="success" type="mock"/>
+        </action>
+
         <action name="TestInterceptorParam" class="org.apache.struts2.SimpleAction">
             <interceptor-ref name="test">
                 <param name="expectedFoo">expectedFoo</param>


(struts) 11/14: WW-3871 docs(core): add deprecated Collection_ prefix to parameter table

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-3871-typeconversion-key-derivation
in repository https://gitbox.apache.org/repos/asf/struts.git

commit f5ce53646d79b41164a07de9cfe77f8523467cfa
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Jul 25 16:54:51 2026 +0200

    WW-3871 docs(core): add deprecated Collection_ prefix to parameter table
---
 .../org/apache/struts2/conversion/annotations/TypeConversion.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
index c65b5d08e..e4f86b965 100644
--- a/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
+++ b/core/src/main/java/org/apache/struts2/conversion/annotations/TypeConversion.java
@@ -69,8 +69,8 @@ import java.lang.annotation.Target;
  * <td>no</td>
  * <td>The annotated property/field name</td>
  * <td>The property name the rule applies to. The matching prefix for the given rule
- * (<code>Key_</code>, <code>Element_</code>, <code>KeyProperty_</code>, <code>CreateIfNull_</code>)
- * is prepended automatically unless the key already carries it. Required on TYPE level annotations,
+ * (<code>Key_</code>, <code>Element_</code>, <code>KeyProperty_</code>, <code>CreateIfNull_</code>, or the deprecated
+ * <code>Collection_</code>) is prepended automatically unless the key already carries it. Required on TYPE level annotations,
  * where there is no member name to derive it from.</td>
  * </tr>
  * <tr>