Skip to content

Conversation

@jujn
Copy link
Contributor

@jujn jujn commented Dec 10, 2025

…ormat, for issue #3864

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

Copilot AI review requested due to automatic review settings December 10, 2025 12:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a conflict where a globally registered Date writer was incorrectly overriding the @JSONField format annotation on Date fields. The fix ensures that when a Date field has a non-empty format specified via @JSONField, the field-specific format takes precedence over the global writer.

  • Modified the condition in ObjectWriterCreator.createFieldWriter() to skip fetching the global writer when a Date field has a format annotation
  • Added a comprehensive test case that verifies both scenarios: Date fields without format use the global writer, while Date fields with format use the specified format

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/src/test/java/com/alibaba/fastjson2/issues_3800/Issue3864.java Added test case demonstrating the fix: registers a global Date writer that outputs timestamps, then verifies that a Date field with @JSONField(format=...) correctly uses its format instead of the global writer
core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterCreator.java Modified conditional logic to prevent global Date writer lookup when a Date field has a non-empty format annotation, allowing the format-specific writer to be used instead

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenshao wenshao merged commit e99f0f9 into alibaba:main Dec 10, 2025
27 checks passed
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.

2 participants