fix: apply JSONReader context to SimpleDateFormat values - #7820
Open
DarrenChangJR wants to merge 1 commit into
Open
fix: apply JSONReader context to SimpleDateFormat values#7820DarrenChangJR wants to merge 1 commit into
DarrenChangJR wants to merge 1 commit into
Conversation
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.
What this PR does and why
The
SimpleDateFormatvalue reader currently invokesSimpleDateFormat::new. It therefore ignores an explicitly configuredJSONReader.Contextlocale and zone, reconstructing the formatter with JVMdefaults instead.
This change replaces that generic constructor adapter with a small dedicated
reader. It keeps the existing string wire representation, uses the context
locale when one is configured, and applies the context zone after construction.
Reproducer
With
Locale.FRANCEandGMT+08set on the reader context, deserializing"MMM"asSimpleDateFormatnow produces a formatter whose time-zone ID isGMT+08:00and which formats epoch zero asjanv.. Previously it producedJanin the JVM time zone.Tests
DateFormatTestandAutoTypeFilterTest2coverage;mvn -pl core -DskipTests validate;Checklist
中文说明
修改内容和原因
当前
SimpleDateFormatvalue reader 通过SimpleDateFormat::new构造对象,因此即使调用方在
JSONReader.Context中明确配置 locale 和时区,重建后的formatter 仍使用 JVM 默认值。
本修改使用一个小型、无状态的专用 reader,保持原有 pattern 字符串 wire form,
在 locale 存在时用它构造 formatter,并设置 context 时区。
测试
回归测试覆盖字符 JSON、UTF-8 JSON 和 JSONB;已有日期与 JSONB auto-type 测试、
Maven validate,以及 clean 后完整 7,977 个 core 测试均通过。