[
https://issues.apache.org/jira/browse/WW-3364?focusedWorklogId=1046742&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1046742
]
ASF GitHub Bot logged work on WW-3364:
--------------------------------------
Author: ASF GitHub Bot
Created on: 10/Oct/26 10:32
Start Date: 10/Oct/26 10:32
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #2002:
URL: https://github.com/apache/struts/pull/2002
Fixes [WW-3364](https://issues.apache.org/jira/browse/WW-3364)
## Summary
The JSON plugin never consulted the type converters an application
registers, so a value type rendered through a converter in the HTML view (e.g.
`Money` → `"12.50 EUR"`) came out as a nested bean in the JSON response.
This adds an opt-in constant, `struts.json.writer.useTypeConverters`
(default `false`). When enabled, `StrutsJSONWriter` serializes a value that is
not a built-in JSON type with the converter registered for its class — or a
superclass/interface, via `XWorkConverter.lookup()` — and writes the result as
a JSON string.
```xml
<constant name="struts.json.writer.useTypeConverters" value="true"/>
```
## Behaviour
- **Off by default** — existing output is unchanged.
- **Built-in types are never converted.** The check sits after the
Boolean/Number/String/Map/Iterable/Date/Temporal/Locale/Enum branches, so
`@JSON(format)` and `struts.json.dateformat` keep working. It runs before the
record branch, so a record value type can have a converter.
- **Only class-level converters** (`struts-conversion.properties` /
`xwork-conversion.properties`, class-level `@TypeConversion`) are used;
per-property `Foo-conversion.properties` mappings need context the writer does
not have.
- `java.io.File` is skipped, so the framework's own `UploadedFileConverter`
is never applied.
- **`@JSONFieldBridge` keeps precedence** — it is applied at the property
level before the value is written.
- **Failure falls back** — if a converter throws or returns a non-String,
the value is serialized as a bean/record as before (logged at debug).
- A converted value is written as a single string: nested
`includeProperties`/`excludeProperties` patterns and `@JSON` annotations on its
members no longer apply to it. This will be stated in the JSON plugin docs.
Out of scope: using converters on the read side (`JSONPopulator`).
## Test plan
- [x] New `StrutsJSONWriterTypeConverterTest` (container-backed,
`StrutsTestCase`): default off, converted value, nested property,
interface-registered converter, record, no converter, field-bridge precedence,
failing converter fallback, built-in types untouched, `File` skipped
- [x] Each guard test was mutation-checked: removing the flag check, the
exception fallback, the `File` exclusion, the built-in ordering, or the field
bridge makes the corresponding test fail
- [x] `./mvnw test -DskipAssembly -pl plugins/json` — 177 tests, 0 failures
Docs: a paragraph for the JSON plugin page follows in apache/struts-site.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1046742)
Remaining Estimate: 0h
Time Spent: 10m
> Using convertors in JSON serialization
> --------------------------------------
>
> Key: WW-3364
> URL: https://issues.apache.org/jira/browse/WW-3364
> Project: Struts 2
> Issue Type: Improvement
> Components: Plugin - JSON
> Affects Versions: 2.1.8
> Reporter: Rahul Mohan
> Assignee: Lukasz Lenart
> Priority: Major
> Labels: JSON
> Fix For: 7.5.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The bundled JSON plugin does not use registered convertors for data
> conversion. This seriously affects the implementation of gracefully degrading
> ajax apps.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)