codeconsole commented on code in PR #16411: URL: https://github.com/apache/grails-core/pull/16411#discussion_r4124774537
########## grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/MonthMarshaller.java: ########## @@ -0,0 +1,49 @@ +/* + * 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.time.Month; + +import grails.converters.JSON; +import org.grails.web.converters.exceptions.ConverterException; +import org.grails.web.converters.marshaller.ObjectMarshaller; +import org.grails.web.json.JSONException; + +/** + * JSON ObjectMarshaller which converts a Month to its number, 1 for January through 12 for December, + * the same as Spring Boot's default Jackson rendering. It is registered ahead of + * {@link SimpleEnumMarshaller}, which would otherwise render the enum name. + * + * @since 8.0 + */ +public class MonthMarshaller implements ObjectMarshaller<JSON> { + + public boolean supports(Object object) { + return object instanceof Month; + } + + public void marshalObject(Object object, JSON converter) throws ConverterException { + try { + converter.getWriter().value(((Month) object).getValue()); Review Comment: Done in f8ef37883d. `Month` renders as `"SEPTEMBER"` in both renderers, and `monthValueConverter` stays. - The `Month` rows and snippets are out of the guides, and the §76.4 enum note covers `Month`. - The guides show a marshaller and a JSON views converter that render its number, as Spring Boot does, and tests cover both. ########## grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/SqlTimeMarshaller.java: ########## @@ -0,0 +1,50 @@ +/* + * 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.sql.Time; + +import grails.converters.JSON; +import org.grails.web.converters.exceptions.ConverterException; +import org.grails.web.converters.marshaller.ObjectMarshaller; +import org.grails.web.json.JSONException; + +/** + * JSON ObjectMarshaller which converts a {@link java.sql.Time} to its wall-clock time in the + * JVM default time zone ({@code HH:mm:ss}, from {@link Time#toString()}), the same as Spring Boot's + * default Jackson rendering. It is registered ahead of {@link DateMarshaller}, which would + * otherwise render the {@code Time} as a full date and time. + * + * @since 8.0 + */ +public class SqlTimeMarshaller implements ObjectMarshaller<JSON> { + + public boolean supports(Object object) { + return object instanceof Time; + } + + public void marshalObject(Object object, JSON converter) throws ConverterException { + try { + converter.getWriter().value(object.toString()); Review Comment: Fixed in 76d01c9dd1: "which binds back to the same time of day, to the second, as with Spring Boot". ########## grails-views-gson/src/main/groovy/grails/plugin/json/view/JsonViewGeneratorConfiguration.groovy: ########## @@ -29,9 +29,20 @@ class JsonViewGeneratorConfiguration { Boolean escapeUnicode = false + /** + * The {@link java.text.SimpleDateFormat} pattern for {@link Date} and {@link Calendar} values and map keys. In the + * default {@link #timeZone} it writes a UTC instant with millisecond precision, such as + * {@code 2024-06-15T14:30:45.123Z}, as Spring Boot does. + */ String dateFormat = /yyyy-MM-dd'T'HH:mm:ss.SSSX/ Review Comment: Done in 09bf0ce708. The default is `yyyy-MM-dd'T'HH:mm:ss.SSSXXX`. - The `timeZone` test compares with `JsonMapper` for `GMT`, `America/New_York`, `Asia/Kolkata` and `Asia/Kathmandu`. - §76.2 has a row for the offset change, and `jsonConfiguration.adoc`, the metadata `defaultValue` and the last §76.4 note are updated. -- 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]
