Repository navigation
WW-3364 Use registered type converters in JSON serialization (opt-in) - #2002
Merged
Merged
Conversation
Adds the opt-in struts.json.writer.useTypeConverters constant (default false). When enabled, StrutsJSONWriter serializes a value that is not a built-in JSON type with the type converter registered for its class (or a superclass/interface) and writes the result as a JSON string, falling back to bean/record serialization when no converter is registered or the converter fails. @JSONFieldBridge keeps precedence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…plexity Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaszlenart
marked this pull request as ready for review
October 10, 2026 10:43
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes 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(defaultfalse). When enabled,StrutsJSONWriterserializes a value that is not a built-in JSON type with the converter registered for its class — or a superclass/interface, viaXWorkConverter.lookup()— and writes the result as a JSON string.Behaviour
@JSON(format)andstruts.json.dateformatkeep working. It runs before the record branch, so a record value type can have a converter.struts-conversion.properties/xwork-conversion.properties,@TypeConversion(type = ConversionType.APPLICATION)) are used; per-propertyFoo-conversion.propertiesmappings need context the writer does not have.java.io.Fileis skipped, so the framework's ownUploadedFileConverteris never applied.@JSONFieldBridgekeeps precedence — it is applied at the property level before the value is written.includeProperties/excludePropertiespatterns and@JSONannotations 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
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,FileskippedFileexclusion, the built-in ordering, or the field bridge makes the corresponding test fail./mvnw test -DskipAssembly -pl plugins/json— 177 tests, 0 failuresDocs: a paragraph for the JSON plugin page follows in apache/struts-site.
🤖 Generated with Claude Code