WW-5641 Restore struts.json.writer / struts.json.reader override in JSON plugin#1766
Open
lukaszlenart wants to merge 3 commits into
Open
WW-5641 Restore struts.json.writer / struts.json.reader override in JSON plugin#1766lukaszlenart wants to merge 3 commits into
lukaszlenart wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48c3060 to
ec4ac87
Compare
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The JSON plugin declared <bean-selection> in struts-plugin.xml, which runs at plugin-parse time, before the application struts.xml is folded in. That froze the JSONWriter/JSONReader default binding to StrutsJSONWriter/Reader, so struts.json.writer / struts.json.reader overrides were ignored. Move the element to struts-deferred.xml, which Dispatcher loads last (after the app config and core's StrutsBeanSelectionProvider), so the alias honors the override. Mirrors the velocity plugin. JSONUtil is unchanged from main. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ec4ac87 to
4ecf29c
Compare
|
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-5641
Problem
A custom JSON writer/reader configured the documented way is silently ignored on the 7.2.x line — the framework always uses the default
StrutsJSONWriter/StrutsJSONReader:This worked on 7.1.x and regressed in 7.2.x. The extension point is still documented at https://struts.apache.org/plugins/json/, so this is a regression, not an intended API change.
Root cause
The 7.2.x JSON hardening rework added a
<bean-selection name="jsonBeans" .../>element to the plugin'sstruts-plugin.xml.XmlDocConfigurationProvider.registerBeanSelection()runs that element inline, at plugin-parse time — before the application'sstruts.xmlfolds its override bean andstruts.json.writerconstant into the sharedprops.AbstractBeanSelectionProvider.alias()binds the default name only once (guarded), so it locksJSONWriter/JSONReader DEFAULT_NAME → StrutsJSONWriter/StrutsJSONReaderand never re-selects when the app config loads afterward.Fix
Move the
<bean-selection>fromstruts-plugin.xmlinto a newstruts-deferred.xml.Dispatcher.init()loadsstruts-deferred.xmllast — after the application config and after core'sStrutsBeanSelectionProvider— precisely because it is "sensitive to loading order such as 'bean-selection' elements" (per the framework's own comment). Running late,alias()reads the effectivestruts.json.writer/struts.json.readervalue and aliases the default binding to the application's override.This is the established in-tree convention: the velocity plugin already keeps its
<bean>definitions instruts-plugin.xmland its<bean-selection>instruts-deferred.xml; core's ownStrutsBeanSelectionProvideris likewise registered to run after all XML config. The JSON plugin was the outlier.JSONUtilis unchanged frommain.StrutsJSONWriter/StrutsJSONReaderremain the shipped defaults when no override is configured; DoS limits untouched.container.getInstance(JSONWriter.class)resolves to the override for any consumer.Test
JSONWriterOverrideTestboots the realDispatcherchain (struts-deferred.xmlis loaded last by the framework, so it is intentionally omitted from the explicitconfig) and asserts, for both writer and reader, at both levels: the default container binding (container.getInstance(...)) and the effective use (JSONUtil.serialize(...)sentinel /getReader().getClass()). Verified failing before the element is moved, passing after. Fullstruts2-json-pluginsuite: 129/129 green;apache-rat:checkclean.🤖 Generated with Claude Code