You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/09/28 02:52:21 UTC
(grails-core) 02/03: Collapse the remaining pre-existing single-type date/time marshallers
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch refactor/16411-marshaller-dedup
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 2e72785cf41c729505853d6484c2f7c57e4a8e48
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sat Sep 26 12:07:33 2026 -0500
Collapse the remaining pre-existing single-type date/time marshallers
Extend the previous commit's generic marshaller/converter to the 5
JSON marshallers and 8 JSON-views converters that predate #16411
(Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime,
OffsetTime, Period, ZonedDateTime), removing the same one-line-of-logic
boilerplate from the pre-existing code, not just the code #16411 added.
These files carried individual @author tags. The repo's established
convention is not to carry personal attribution in source (recent
examples: e6fa4eb973, 59d78b298e, b7ab39b519, 87fb2694d1, and
17debfa49c removing a real author's name/email from a plugin
descriptor "as this information is not necessary for core plugins") —
git history is the attribution record, so dropping them here follows
existing practice rather than breaking from it.
Verified behavior-preserving the same way as the previous commit:
grails-converters (195 tests) and grails-views-gson (266 tests) pass
unchanged, checkstyle/CodeNarc clean on both modules.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../ConvertersConfigurationInitializer.java | 15 ++++---
.../marshaller/json/InstantMarshaller.java | 49 ----------------------
.../marshaller/json/LocalDateMarshaller.java | 49 ----------------------
.../marshaller/json/LocalDateTimeMarshaller.java | 49 ----------------------
.../marshaller/json/OffsetDateTimeMarshaller.java | 49 ----------------------
.../marshaller/json/ZonedDateTimeMarshaller.java | 49 ----------------------
.../json/converters/InstantJsonConverter.groovy | 45 --------------------
.../json/converters/LocalDateJsonConverter.groovy | 45 --------------------
.../converters/LocalDateTimeJsonConverter.groovy | 45 --------------------
.../json/converters/LocalTimeJsonConverter.groovy | 45 --------------------
.../converters/OffsetDateTimeJsonConverter.groovy | 45 --------------------
.../json/converters/OffsetTimeJsonConverter.groovy | 45 --------------------
.../json/converters/PeriodJsonConverter.groovy | 44 -------------------
.../converters/ZonedDateTimeJsonConverter.groovy | 45 --------------------
.../plugin/json/view/JsonViewTemplateEngine.groovy | 33 ++++++++-------
15 files changed, 27 insertions(+), 625 deletions(-)
diff --git a/grails-converters/src/main/groovy/org/grails/web/converters/configuration/ConvertersConfigurationInitializer.java b/grails-converters/src/main/groovy/org/grails/web/converters/configuration/ConvertersConfigurationInitializer.java
index e42123f551..c32cdde815 100644
--- a/grails-converters/src/main/groovy/org/grails/web/converters/configuration/ConvertersConfigurationInitializer.java
+++ b/grails-converters/src/main/groovy/org/grails/web/converters/configuration/ConvertersConfigurationInitializer.java
@@ -20,14 +20,19 @@ package org.grails.web.converters.configuration;
import java.sql.Time;
import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.MonthDay;
+import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneId;
+import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -140,13 +145,13 @@ public class ConvertersConfigurationInitializer implements ApplicationContextAwa
marshallers.add(new org.grails.web.converters.marshaller.json.CalendarMarshaller());
marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(XMLGregorianCalendar.class,
calendar -> JsonDateFormat.format(calendar.toGregorianCalendar().getTimeInMillis())));
- marshallers.add(new org.grails.web.converters.marshaller.json.InstantMarshaller());
- marshallers.add(new org.grails.web.converters.marshaller.json.LocalDateMarshaller());
- marshallers.add(new org.grails.web.converters.marshaller.json.LocalDateTimeMarshaller());
+ marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(Instant.class, DateTimeFormatter.ISO_INSTANT::format));
+ marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(LocalDate.class, DateTimeFormatter.ISO_LOCAL_DATE::format));
+ marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(LocalDateTime.class, DateTimeFormatter.ISO_LOCAL_DATE_TIME::format));
marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(LocalTime.class, DateTimeFormatter.ISO_LOCAL_TIME::format));
- marshallers.add(new org.grails.web.converters.marshaller.json.OffsetDateTimeMarshaller());
+ marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME::format));
marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(OffsetTime.class, OffsetTime::toString));
- marshallers.add(new org.grails.web.converters.marshaller.json.ZonedDateTimeMarshaller());
+ marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(ZonedDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME::format));
marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(Year.class, Year::getValue));
marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(YearMonth.class, YearMonth::toString));
marshallers.add(new org.grails.web.converters.marshaller.json.SimpleTypeMarshaller<>(MonthDay.class, MonthDay::toString));
diff --git a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/InstantMarshaller.java b/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/InstantMarshaller.java
deleted file mode 100644
index 15b2e7ef90..0000000000
--- a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/InstantMarshaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.Instant;
-import java.time.format.DateTimeFormatter;
-
-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 an Instant to ISO-8601 format with Z suffix.
- *
- * @since 7.0
- */
-public class InstantMarshaller implements ObjectMarshaller<JSON> {
-
- public boolean supports(Object object) {
- return object instanceof Instant;
- }
-
- public void marshalObject(Object object, JSON converter) throws ConverterException {
- try {
- Instant instant = (Instant) object;
- converter.getWriter().value(DateTimeFormatter.ISO_INSTANT.format(instant));
- }
- catch (JSONException e) {
- throw new ConverterException(e);
- }
- }
-}
diff --git a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/LocalDateMarshaller.java b/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/LocalDateMarshaller.java
deleted file mode 100644
index 5e669f02bd..0000000000
--- a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/LocalDateMarshaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.LocalDate;
-import java.time.format.DateTimeFormatter;
-
-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 LocalDate to ISO-8601 date format (YYYY-MM-DD).
- *
- * @since 7.0
- */
-public class LocalDateMarshaller implements ObjectMarshaller<JSON> {
-
- public boolean supports(Object object) {
- return object instanceof LocalDate;
- }
-
- public void marshalObject(Object object, JSON converter) throws ConverterException {
- try {
- LocalDate localDate = (LocalDate) object;
- converter.getWriter().value(DateTimeFormatter.ISO_LOCAL_DATE.format(localDate));
- }
- catch (JSONException e) {
- throw new ConverterException(e);
- }
- }
-}
diff --git a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/LocalDateTimeMarshaller.java b/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/LocalDateTimeMarshaller.java
deleted file mode 100644
index e03d8bdcdd..0000000000
--- a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/LocalDateTimeMarshaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-
-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 LocalDateTime to ISO-8601 format (without timezone).
- *
- * @since 7.0
- */
-public class LocalDateTimeMarshaller implements ObjectMarshaller<JSON> {
-
- public boolean supports(Object object) {
- return object instanceof LocalDateTime;
- }
-
- public void marshalObject(Object object, JSON converter) throws ConverterException {
- try {
- LocalDateTime localDateTime = (LocalDateTime) object;
- converter.getWriter().value(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(localDateTime));
- }
- catch (JSONException e) {
- throw new ConverterException(e);
- }
- }
-}
diff --git a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/OffsetDateTimeMarshaller.java b/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/OffsetDateTimeMarshaller.java
deleted file mode 100644
index 83c84d680a..0000000000
--- a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/OffsetDateTimeMarshaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.OffsetDateTime;
-import java.time.format.DateTimeFormatter;
-
-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 an OffsetDateTime to ISO-8601 format with timezone offset.
- *
- * @since 7.0
- */
-public class OffsetDateTimeMarshaller implements ObjectMarshaller<JSON> {
-
- public boolean supports(Object object) {
- return object instanceof OffsetDateTime;
- }
-
- public void marshalObject(Object object, JSON converter) throws ConverterException {
- try {
- OffsetDateTime offsetDateTime = (OffsetDateTime) object;
- converter.getWriter().value(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetDateTime));
- }
- catch (JSONException e) {
- throw new ConverterException(e);
- }
- }
-}
diff --git a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/ZonedDateTimeMarshaller.java b/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/ZonedDateTimeMarshaller.java
deleted file mode 100644
index d65b420105..0000000000
--- a/grails-converters/src/main/groovy/org/grails/web/converters/marshaller/json/ZonedDateTimeMarshaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-
-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 ZonedDateTime to ISO-8601 format with timezone offset.
- *
- * @since 7.0
- */
-public class ZonedDateTimeMarshaller implements ObjectMarshaller<JSON> {
-
- public boolean supports(Object object) {
- return object instanceof ZonedDateTime;
- }
-
- public void marshalObject(Object object, JSON converter) throws ConverterException {
- try {
- ZonedDateTime zonedDateTime = (ZonedDateTime) object;
- converter.getWriter().value(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime));
- }
- catch (JSONException e) {
- throw new ConverterException(e);
- }
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/InstantJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/InstantJsonConverter.groovy
deleted file mode 100644
index 15411f5714..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/InstantJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.Instant
-import java.time.format.DateTimeFormatter
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link java.time.Instant} as json
- *
- * @author James Kleeh
- */
-@CompileStatic
-class InstantJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- Instant == type
- }
-
- @Override
- Object convert(Object value, String key) {
- DateTimeFormatter.ISO_INSTANT.format((Instant) value)
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalDateJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalDateJsonConverter.groovy
deleted file mode 100644
index 72b565e3cd..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalDateJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.LocalDate
-import java.time.format.DateTimeFormatter
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link LocalDate} as json
- *
- * @author James Kleeh
- */
-@CompileStatic
-class LocalDateJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- LocalDate == type
- }
-
- @Override
- Object convert(Object value, String key) {
- DateTimeFormatter.ISO_LOCAL_DATE.format((LocalDate) value)
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalDateTimeJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalDateTimeJsonConverter.groovy
deleted file mode 100644
index b8448d26a7..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalDateTimeJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.LocalDateTime
-import java.time.format.DateTimeFormatter
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link LocalDateTime} as json
- *
- * @author James Kleeh
- */
-@CompileStatic
-class LocalDateTimeJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- LocalDateTime == type
- }
-
- @Override
- Object convert(Object value, String key) {
- DateTimeFormatter.ISO_LOCAL_DATE_TIME.format((LocalDateTime) value)
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalTimeJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalTimeJsonConverter.groovy
deleted file mode 100644
index a98a0726a7..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/LocalTimeJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.LocalTime
-import java.time.format.DateTimeFormatter
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link LocalTime} as json
- *
- * @author James Kleeh
- */
-@CompileStatic
-class LocalTimeJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- LocalTime == type
- }
-
- @Override
- Object convert(Object value, String key) {
- DateTimeFormatter.ISO_LOCAL_TIME.format((LocalTime) value)
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/OffsetDateTimeJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/OffsetDateTimeJsonConverter.groovy
deleted file mode 100644
index ad64b89227..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/OffsetDateTimeJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.OffsetDateTime
-import java.time.format.DateTimeFormatter
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link OffsetDateTime} as json
- *
- * @author James Kleeh
- */
-@CompileStatic
-class OffsetDateTimeJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- OffsetDateTime == type
- }
-
- @Override
- Object convert(Object value, String key) {
- DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((OffsetDateTime) value)
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/OffsetTimeJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/OffsetTimeJsonConverter.groovy
deleted file mode 100644
index 010ddb6245..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/OffsetTimeJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.OffsetTime
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link OffsetTime} as json: its ISO-8601 {@link OffsetTime#toString()} form
- * (e.g. {@code 03:00-03:00}), the same as Spring Boot's default Jackson rendering.
- *
- * @author James Kleeh
- */
-@CompileStatic
-class OffsetTimeJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- OffsetTime == type
- }
-
- @Override
- Object convert(Object value, String key) {
- value.toString()
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/PeriodJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/PeriodJsonConverter.groovy
deleted file mode 100644
index fc006eeb15..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/PeriodJsonConverter.groovy
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.Period
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link Period} as json
- *
- * @author Muhammad Hamza Zaib
- */
-@CompileStatic
-class PeriodJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- Period == type
- }
-
- @Override
- Object convert(Object value, String key) {
- ((Period) value).toString()
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/ZonedDateTimeJsonConverter.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/converters/ZonedDateTimeJsonConverter.groovy
deleted file mode 100644
index 49eb0381df..0000000000
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/converters/ZonedDateTimeJsonConverter.groovy
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 grails.plugin.json.converters
-
-import java.time.ZonedDateTime
-import java.time.format.DateTimeFormatter
-
-import groovy.json.JsonGenerator
-import groovy.transform.CompileStatic
-
-/**
- * A class to render a {@link ZonedDateTime} as json
- *
- * @author James Kleeh
- */
-@CompileStatic
-class ZonedDateTimeJsonConverter implements JsonGenerator.Converter {
-
- @Override
- boolean handles(Class<?> type) {
- ZonedDateTime == type
- }
-
- @Override
- Object convert(Object value, String key) {
- DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((ZonedDateTime) value)
- }
-}
diff --git a/grails-views-gson/src/main/groovy/grails/plugin/json/view/JsonViewTemplateEngine.groovy b/grails-views-gson/src/main/groovy/grails/plugin/json/view/JsonViewTemplateEngine.groovy
index 934fac7f73..45ab605d5b 100644
--- a/grails-views-gson/src/main/groovy/grails/plugin/json/view/JsonViewTemplateEngine.groovy
+++ b/grails-views-gson/src/main/groovy/grails/plugin/json/view/JsonViewTemplateEngine.groovy
@@ -21,11 +21,20 @@ package grails.plugin.json.view
import java.sql.Time
import java.time.Duration
+import java.time.Instant
+import java.time.LocalDate
+import java.time.LocalDateTime
+import java.time.LocalTime
import java.time.Month
import java.time.MonthDay
+import java.time.OffsetDateTime
+import java.time.OffsetTime
+import java.time.Period
import java.time.Year
import java.time.YearMonth
import java.time.ZoneId
+import java.time.ZonedDateTime
+import java.time.format.DateTimeFormatter
import java.util.function.Function
import javax.xml.datatype.XMLGregorianCalendar
@@ -39,15 +48,7 @@ import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.OrderComparator
-import grails.plugin.json.converters.InstantJsonConverter
-import grails.plugin.json.converters.LocalDateJsonConverter
-import grails.plugin.json.converters.LocalDateTimeJsonConverter
-import grails.plugin.json.converters.LocalTimeJsonConverter
-import grails.plugin.json.converters.OffsetDateTimeJsonConverter
-import grails.plugin.json.converters.OffsetTimeJsonConverter
-import grails.plugin.json.converters.PeriodJsonConverter
import grails.plugin.json.converters.SimpleTypeJsonConverter
-import grails.plugin.json.converters.ZonedDateTimeJsonConverter
import grails.plugin.json.view.api.jsonapi.JsonApiIdRenderStrategy
import grails.plugin.json.view.internal.JsonTemplateTypeCheckingExtension
import grails.plugin.json.view.internal.JsonViewsTransform
@@ -119,15 +120,15 @@ class JsonViewTemplateEngine extends ResolvableGroovyTemplateEngine {
Map<String, JsonGenerator.Converter> convertersByClass = new LinkedHashMap<>()
registerConverters(ServiceLoader.load(JsonGenerator.Converter, classLoader), convertersByClass)
List<JsonGenerator.Converter> converters = new ArrayList<>(convertersByClass.values())
- converters.add(new InstantJsonConverter())
- converters.add(new LocalDateJsonConverter())
- converters.add(new LocalDateTimeJsonConverter())
- converters.add(new LocalTimeJsonConverter())
- converters.add(new OffsetDateTimeJsonConverter())
- converters.add(new OffsetTimeJsonConverter())
- converters.add(new PeriodJsonConverter())
+ converters.add(new SimpleTypeJsonConverter(Instant, { DateTimeFormatter.ISO_INSTANT.format((Instant) it) } as Function))
+ converters.add(new SimpleTypeJsonConverter(LocalDate, { DateTimeFormatter.ISO_LOCAL_DATE.format((LocalDate) it) } as Function))
+ converters.add(new SimpleTypeJsonConverter(LocalDateTime, { DateTimeFormatter.ISO_LOCAL_DATE_TIME.format((LocalDateTime) it) } as Function))
+ converters.add(new SimpleTypeJsonConverter(LocalTime, { DateTimeFormatter.ISO_LOCAL_TIME.format((LocalTime) it) } as Function))
+ converters.add(new SimpleTypeJsonConverter(OffsetDateTime, { DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((OffsetDateTime) it) } as Function))
+ converters.add(new SimpleTypeJsonConverter(OffsetTime, { it.toString() } as Function))
+ converters.add(new SimpleTypeJsonConverter(Period, { it.toString() } as Function))
converters.add(new SimpleTypeJsonConverter(Time, { it.toString() } as Function))
- converters.add(new ZonedDateTimeJsonConverter())
+ converters.add(new SimpleTypeJsonConverter(ZonedDateTime, { DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((ZonedDateTime) it) } as Function))
converters.add(new SimpleTypeJsonConverter(Year, { ((Year) it).value } as Function))
converters.add(new SimpleTypeJsonConverter(YearMonth, { it.toString() } as Function))
converters.add(new SimpleTypeJsonConverter(MonthDay, { it.toString() } as Function))