Skip to content

10.0: Resolve Grails formats with Spring MVC's content negotiation by default - #17106

Draft
codeconsole wants to merge 3 commits into
apache:10.0.xfrom
codeconsole:feat/spring-format-negotiation-default-10.0.x
Draft

codeconsole wants to merge 3 commits into
apache:10.0.xfrom
codeconsole:feat/spring-format-negotiation-default-10.0.x

Conversation

@codeconsole

@codeconsole codeconsole commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Makes grails.mime.negotiation.spring (#16996) the default in Grails 10, as the Grails 9 upgrade guide announces. Completes #16698.

request.format, response.format, withFormat and the format respond writes in are now resolved with Spring MVC's content negotiation manager by default, so the spring.mvc.contentnegotiation.* settings apply to them, and the format parameter, URL extensions and the grails.mime settings of the Accept header decide what Spring MVC writes for an action too. A Spring MVC endpoint, and Spring Security's filters before a URL mapping has matched a request, negotiate as before.

An application keeps the Grails rules with:

grails:
    mime:
        negotiation:
            spring: false

Changes

  • Settings.MIME_NEGOTIATION_SPRING_DEFAULT and the configuration metadata are true; every reader of the setting follows the constant. The URL mappings plugin falls back to the default, not to false, where it has no configuration.
  • Specs that pin the Grails rules set the setting to false, which keeps them: RequestAndResponseMimeTypesApiSpec, GrailsFormatNegotiationRespondSpec, ProblemDetailContentNegotiationSpec, and a new XmlProblemDetailGrailsRulesSpec. Specs about the default state it: SpringFormatNegotiationSpec, UrlMappingsGrailsPluginSpec, ControllerJsonSerializationSpec (a map is answered 406 for an Accept header Spring cannot read).
  • The spring-format-negotiation test app runs the default, and app1's GrailsFormatNegotiationSpec, which pins the Grails rules, moves there under @TestPropertySource(properties = 'grails.mime.negotiation.spring=false'). app1 has GORM, where a second test context breaks the GORM specs after it; that app has none. app1's whole suite now runs the default.
  • Docs: the content negotiation section describes Spring MVC's manager as how Grails resolves formats, with false keeping the Grails rules; the configuration option gives the new default; the Grails 9 to 10 upgrade guide gains section 3 (anchor upgradingSpringFormatNegotiationDefault) with the answers that change and how to keep the Grails rules, and lists the setting as changed in its announced-defaults table. The Grails 10 grails-upgrade skill covers the change the same way.

Depends on #17102

WithFormatSpec's feature for Accept: application/problem+xml, application/atom+xml (answered atom, as in Grails 8) fails here until #17102 reaches 10.0.x: with the setting, the +xml preference did not take an unconfigured application/problem+xml as the XML type. #17102 fixes that on 9.0.x. This pull request stays a draft until then. Merge order:

  1. 9.0 (fix): Spring format negotiation follow-ups: problem+xml ordering, fallback wording #17102 into 9.0.x.
  2. 9.0.x into 9.1.x, then 9.1.x into 10.0.x.
  3. Mark this pull request ready for review, which starts CI.
  4. After it merges, close Resolve Grails formats through Spring MVC's content negotiation #16698 by hand: GitHub closes an issue from a pull request only into the default branch (8.0.x).

grails.mime.negotiation.spring now defaults to true, as Grails 9
announced (apache#16698). Settings.MIME_NEGOTIATION_SPRING_DEFAULT and the
configuration metadata say true, and every reader of the setting follows
the constant. The URL mappings plugin no longer turns a missing
configuration into false: it falls back to the default.

The specs that pin the Grails rules set the setting to false, which keeps
them: RequestAndResponseMimeTypesApiSpec, GrailsFormatNegotiationRespondSpec,
ProblemDetailContentNegotiationSpec, and a new XmlProblemDetailGrailsRulesSpec
for the lenient reading of an Accept header Spring cannot read, which
GrailsFormatNegotiationRespondSpec now covers for a map too.
SpringFormatNegotiationSpec and UrlMappingsGrailsPluginSpec state the new
default, and ControllerJsonSerializationSpec expects a map to be answered
406 for an Accept header Spring cannot read.
The spring-format-negotiation test app no longer sets
grails.mime.negotiation.spring, so its SpringFormatNegotiationSpec runs
the Grails 10 default end to end. app1's GrailsFormatNegotiationSpec,
which pins the Grails rules, moves to that app with
@TestPropertySource(grails.mime.negotiation.spring=false), along with the
end of app1's SpringWrittenController, which only it used. app1 has GORM,
where a second test context breaks every later GORM spec; the format
negotiation app has none. app1 now runs the default too.
The content negotiation section describes Spring MVC's manager as how
Grails resolves formats, with false keeping the Grails rules, and notes
that the Accept header rules above it are those rules. The configuration
option gives the new default. The Grails 9 to 10 upgrade guide gains
section 3 on the change, with the answers that differ and how to keep the
Grails rules, and its announced-defaults table lists the setting as
changed. The grails-upgrade skill covers the change the same way.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant