-
-
Notifications
You must be signed in to change notification settings - Fork 971
7.0.7 + Java 25: Fix for WARNING: Use of the three-letter time zone ID ... is deprecated and it will be removed in a future release #15432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.0.x
Are you sure you want to change the base?
Changes from all commits
2fcf832
ba0835b
6c3e9b1
5f368fe
66ed763
95dc9c2
e4b640a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,10 +19,10 @@ | |||||
| package org.grails.web.converters.marshaller.xml; | ||||||
|
|
||||||
| import java.text.Format; | ||||||
| import java.time.ZoneId; | ||||||
| import java.time.format.DateTimeFormatter; | ||||||
| import java.util.Date; | ||||||
|
|
||||||
| import org.apache.commons.lang3.time.FastDateFormat; | ||||||
|
|
||||||
| import grails.converters.XML; | ||||||
| import org.grails.web.converters.ConverterUtil; | ||||||
| import org.grails.web.converters.exceptions.ConverterException; | ||||||
|
|
@@ -34,21 +34,25 @@ | |||||
| */ | ||||||
| public class DateMarshaller implements ObjectMarshaller<XML> { | ||||||
|
|
||||||
| private final Format formatter; | ||||||
| private static final DateTimeFormatter DEFAULT_FORMATTER = | ||||||
| DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS z") | ||||||
|
||||||
| DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS z") | |
| DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S z") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to revert or justify and add documentation for this change.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.grails.web.converters.marshaller.json | ||
|
|
||
| import java.text.SimpleDateFormat | ||
|
|
||
| import grails.converters.JSON | ||
|
|
||
| import org.grails.web.json.JSONWriter | ||
|
|
||
| import spock.lang.Specification | ||
|
|
||
| class CalendarMarshallerSpec extends Specification { | ||
|
|
||
| void "supports returns true for Calendar instances"() { | ||
| given: | ||
| def marshaller = new CalendarMarshaller() | ||
|
|
||
| expect: | ||
| marshaller.supports(Calendar.getInstance()) | ||
| marshaller.supports(new GregorianCalendar()) | ||
| } | ||
|
|
||
| void "supports returns false for non-Calendar instances"() { | ||
| given: | ||
| def marshaller = new CalendarMarshaller() | ||
|
|
||
| expect: | ||
| !marshaller.supports(new Date()) | ||
| !marshaller.supports("not a calendar") | ||
| !marshaller.supports(null) | ||
| } | ||
|
|
||
| void "default formatter produces ISO-8601 UTC format with Z suffix"() { | ||
| given: | ||
| def marshaller = new CalendarMarshaller() | ||
| def calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")) | ||
| calendar.setTimeInMillis(1718461845123L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, calendar) | ||
|
|
||
| then: | ||
| result == '["2024-06-15T14:30:45.123Z"]' | ||
| } | ||
|
|
||
| void "default formatter converts non-UTC calendar to UTC"() { | ||
| given: | ||
| def marshaller = new CalendarMarshaller() | ||
| def calendar = Calendar.getInstance(TimeZone.getTimeZone("America/New_York")) | ||
| calendar.setTimeInMillis(1718461845123L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, calendar) | ||
|
|
||
| then: "output is always UTC regardless of calendar timezone" | ||
| result == '["2024-06-15T14:30:45.123Z"]' | ||
| } | ||
|
|
||
| void "default formatter pads milliseconds to three digits"() { | ||
| given: | ||
| def marshaller = new CalendarMarshaller() | ||
| def calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")) | ||
| calendar.setTimeInMillis(1704067200005L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, calendar) | ||
|
|
||
| then: | ||
| result == '["2024-01-01T00:00:00.005Z"]' | ||
| } | ||
|
|
||
| void "legacy formatter is used when provided"() { | ||
| given: | ||
| def customFormat = new SimpleDateFormat("dd/MM/yyyy") | ||
| customFormat.setTimeZone(TimeZone.getTimeZone("UTC")) | ||
| def marshaller = new CalendarMarshaller(customFormat) | ||
| def calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")) | ||
| calendar.setTimeInMillis(1718461845123L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, calendar) | ||
|
|
||
| then: | ||
| result == '["15/06/2024"]' | ||
| } | ||
|
|
||
| private static String marshalToString(CalendarMarshaller marshaller, Calendar calendar) { | ||
| def json = new JSON() | ||
| def stringWriter = new StringWriter() | ||
| json.writer = new JSONWriter(stringWriter) | ||
| json.writer.array() | ||
| marshaller.marshalObject(calendar, json) | ||
| json.writer.endArray() | ||
| stringWriter.toString() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.grails.web.converters.marshaller.json | ||
|
|
||
| import java.text.SimpleDateFormat | ||
|
|
||
| import grails.converters.JSON | ||
|
|
||
| import org.grails.web.json.JSONWriter | ||
|
|
||
| import spock.lang.Specification | ||
|
|
||
| class DateMarshallerSpec extends Specification { | ||
|
|
||
| void "supports returns true for Date instances"() { | ||
| given: | ||
| def marshaller = new DateMarshaller() | ||
|
|
||
| expect: | ||
| marshaller.supports(new Date()) | ||
| } | ||
|
|
||
| void "supports returns false for non-Date instances"() { | ||
| given: | ||
| def marshaller = new DateMarshaller() | ||
|
|
||
| expect: | ||
| !marshaller.supports("not a date") | ||
| !marshaller.supports(42) | ||
| !marshaller.supports(null) | ||
| } | ||
|
|
||
| void "default formatter produces ISO-8601 UTC format with Z suffix"() { | ||
| given: | ||
| def marshaller = new DateMarshaller() | ||
| def date = new Date(1718461845123L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, date) | ||
|
|
||
| then: | ||
| result == '["2024-06-15T14:30:45.123Z"]' | ||
| } | ||
|
|
||
| void "default formatter formats zero milliseconds correctly"() { | ||
| given: | ||
| def marshaller = new DateMarshaller() | ||
| // 2024-01-01T00:00:00.000 UTC | ||
| def date = new Date(1704067200000L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, date) | ||
|
|
||
| then: | ||
| result == '["2024-01-01T00:00:00.000Z"]' | ||
| } | ||
|
|
||
| void "default formatter pads milliseconds to three digits"() { | ||
| given: | ||
| def marshaller = new DateMarshaller() | ||
| // 5 milliseconds past epoch second | ||
| def date = new Date(1704067200005L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, date) | ||
|
|
||
| then: | ||
| result == '["2024-01-01T00:00:00.005Z"]' | ||
| } | ||
|
|
||
| void "legacy formatter is used when provided"() { | ||
| given: | ||
| def customFormat = new SimpleDateFormat("dd/MM/yyyy") | ||
| customFormat.setTimeZone(TimeZone.getTimeZone("UTC")) | ||
| def marshaller = new DateMarshaller(customFormat) | ||
| def date = new Date(1718461845123L) | ||
|
|
||
| when: | ||
| def result = marshalToString(marshaller, date) | ||
|
|
||
| then: | ||
| result == '["15/06/2024"]' | ||
| } | ||
|
|
||
| private static String marshalToString(DateMarshaller marshaller, Date date) { | ||
| def json = new JSON() | ||
| def stringWriter = new StringWriter() | ||
| json.writer = new JSONWriter(stringWriter) | ||
| json.writer.array() | ||
| marshaller.marshalObject(date, json) | ||
| json.writer.endArray() | ||
| stringWriter.toString() | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any known performance problems with the java.time.DateTimeFormatter vs the FastDateTimeFormatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTimeFormatter is ~15% faster based on the following
https://gist.github.com/akostadinov/670a4dc93485128efb6023f5fa319521
https://martin-grigorov.medium.com/compare-performance-of-javas-simpledateformat-against-datetimeformatter-31be58cadf1d