matrei commented on code in PR #15432:
URL: https://github.com/apache/grails-core/pull/15432#discussion_r3156295756
##########
grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/CalendarMarshaller.java:
##########
@@ -37,21 +36,25 @@
*/
public class CalendarMarshaller implements ObjectMarshaller<JSON> {
- private final Format formatter;
+ private static final DateTimeFormatter DEFAULT_FORMATTER =
+ DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
Locale.US)
+ .withZone(ZoneOffset.UTC);
+
+ private final Format legacyFormatter;
/**
* Constructor with a custom formatter.
* @param formatter the formatter
*/
public CalendarMarshaller(Format formatter) {
- this.formatter = formatter;
+ this.legacyFormatter = formatter;
}
/**
* Default constructor.
*/
public CalendarMarshaller() {
- this(FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
TimeZone.getTimeZone("GMT"), Locale.US));
+ this.legacyFormatter = null;
Review Comment:
Invoke/chain the other constructor to tighten things up?
```java
this(null);
```
##########
grails-test-examples/app1/src/integration-test/groovy/functionaltests/marshaller/DateMarshallerSpec.groovy:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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 functionaltests.marshaller
+
+import groovy.json.JsonSlurper
+
+import java.time.Instant
+import java.time.ZoneId
+import java.time.format.DateTimeFormatter
+import io.micronaut.http.HttpRequest
+import io.micronaut.http.HttpStatus
+import io.micronaut.http.MediaType
+import io.micronaut.http.client.HttpClient
+import spock.lang.Narrative
+import spock.lang.Shared
+import spock.lang.Specification
+
+import grails.testing.mixin.integration.Integration
+
+/**
+ * Functional tests verifying that Date and Calendar objects are marshalled
+ * through the Grails JSON and XML converters using DateTimeFormatter.
+ *
+ * These tests exercise the DateTimeFormatter-based marshallers:
+ * - org.grails.web.converters.marshaller.json.DateMarshaller (ISO 8601 UTC)
+ * - org.grails.web.converters.marshaller.json.CalendarMarshaller (ISO 8601
UTC)
+ * - org.grails.web.converters.marshaller.xml.DateMarshaller (system default
timezone)
+ *
+ * JSON format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' (always UTC)
+ * XML format: yyyy-MM-dd HH:mm:ss.SSS z (system default timezone)
+ */
+@Integration
+@Narrative('''
+Grails converters marshal Date and Calendar objects using DateTimeFormatter.
+JSON output uses ISO 8601 UTC format. XML output uses system default timezone.
+Both produce consistent 3-digit millisecond formatting (.000, .123, etc.).
+''')
+class DateMarshallerSpec extends Specification {
+
+ @Shared
+ HttpClient client
Review Comment:
We can switch to `HttpClientSupport` when this branch is updated.
##########
grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/DateMarshaller.java:
##########
@@ -39,21 +38,25 @@
*/
public class DateMarshaller implements ObjectMarshaller<JSON> {
- private final Format formatter;
+ private static final DateTimeFormatter DEFAULT_FORMATTER =
+ DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
Locale.US)
+ .withZone(ZoneOffset.UTC);
+
+ private final Format legacyFormatter;
/**
* Constructor with a custom formatter.
* @param formatter the formatter
*/
public DateMarshaller(Format formatter) {
- this.formatter = formatter;
+ this.legacyFormatter = formatter;
}
/**
* Default constructor.
*/
public DateMarshaller() {
- this(FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
TimeZone.getTimeZone("GMT"), Locale.US));
+ this.legacyFormatter = null;
Review Comment:
Invoke/chain other constructor?
##########
grails-converters/src/main/groovy/org/grails/web/converters/marshaller/xml/DateMarshaller.java:
##########
@@ -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")
+ .withZone(ZoneId.systemDefault());
+
+ private final Format legacyFormatter;
/**
* Constructor with a custom formatter.
* @param formatter the formatter
*/
public DateMarshaller(Format formatter) {
- this.formatter = formatter;
+ this.legacyFormatter = formatter;
}
/**
* Default constructor.
*/
public DateMarshaller() {
- this(FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.S z"));
+ this.legacyFormatter = null;
Review Comment:
Invoke/chain other constructor?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]